mirror of https://github.com/wg-easy/wg-easy
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
721 B
30 lines
721 B
export default defineEventHandler(async (event) => {
|
|
const session = await useWGSession(event);
|
|
const { password } = await readValidatedBody(
|
|
event,
|
|
validateZod(passwordType)
|
|
);
|
|
|
|
if (!REQUIRES_PASSWORD) {
|
|
// if no password is required, the API should never be called.
|
|
// Do not automatically authenticate the user.
|
|
throw createError({
|
|
statusCode: 401,
|
|
statusMessage: 'Invalid state',
|
|
});
|
|
}
|
|
if (!isPasswordValid(password)) {
|
|
throw createError({
|
|
statusCode: 401,
|
|
statusMessage: 'Incorrect Password',
|
|
});
|
|
}
|
|
|
|
const data = await session.update({
|
|
authenticated: true,
|
|
});
|
|
|
|
SERVER_DEBUG(`New Session: ${data.id}`);
|
|
|
|
return { success: true };
|
|
});
|
|
|