Skip to content

Commit

Permalink
feat: add redirect to the sign-in page if verify token is invalid (#262)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyevskii and qwoud committed Jan 19, 2024
1 parent ce30cb1 commit 6a8f378
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ interface ValidatedData extends z.infer<typeof schema> {
async function validator(ctx: AppKoaContext<ValidatedData>, next: Next) {
const user = await userService.findOne({ signupToken: ctx.validatedData.token });

ctx.assertClientError(user, { token: 'Token is invalid' }, 404);
if (!user) {
ctx.redirect(`${config.WEB_URL}/sign-in`);

return;
}

ctx.validatedData.user = user;
await next();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ interface ValidatedData extends z.infer<typeof schema> {
async function validator(ctx: AppKoaContext<ValidatedData>, next: Next) {
const user = await userService.findOne({ signupToken: ctx.validatedData.token });

ctx.assertClientError(user, { token: 'Token is invalid' }, 404);
if (!user) {
ctx.redirect(`${config.WEB_URL}/sign-in`);

return;
}

ctx.validatedData.user = user;
await next();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ interface ValidatedData extends z.infer<typeof schema> {
async function validator(ctx: AppKoaContext<ValidatedData>, next: Next) {
const user = await userService.findOne({ signupToken: ctx.validatedData.token });

ctx.assertClientError(user, { token: 'Token is invalid' }, 404);
if (!user) {
ctx.redirect(`${config.WEB_URL}/sign-in`);

return;
}

ctx.validatedData.user = user;
await next();
Expand Down

0 comments on commit 6a8f378

Please sign in to comment.