Skip to content

Commit

Permalink
fix(page): Redirect to verify email page if email unverified
Browse files Browse the repository at this point in the history
Signed-off-by: Muhammad Naufal <me@falkia34.dev>
  • Loading branch information
falkia34 committed Jul 20, 2024
1 parent b15c5ff commit cfbd29c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
5 changes: 4 additions & 1 deletion app/(auth)/login/page.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ForbiddenError } from '@/domain/errors';
import { GetUser } from '@/application/server';
import { LoginForm } from '@/presentation/components/auth/login';
import { Metadata } from 'next';
Expand All @@ -23,7 +24,9 @@ export default async function LoginPage({ searchParams }: Props) {
try {
user = await getUser.execute();
} catch (error) {
// Do nothing
if (error instanceof ForbiddenError && error.message.includes('not verified')) {
redirect(`/verify-email?callback_url=${searchParams.callback_url}`);
}
}

if (user) {
Expand Down
5 changes: 4 additions & 1 deletion app/(auth)/register/page.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ForbiddenError } from '@/domain/errors';
import { GetUser } from '@/application/server';
import { Metadata } from 'next';
import { redirect } from 'next/navigation';
Expand All @@ -23,7 +24,9 @@ export default async function RegisterPage({ searchParams }: Props) {
try {
user = await getUser.execute();
} catch (error) {
// Do nothing
if (error instanceof ForbiddenError && error.message.includes('not verified')) {
redirect(`/verify-email?callback_url=${searchParams.callback_url}`);
}
}

if (user) {
Expand Down
6 changes: 5 additions & 1 deletion app/(auth)/reset-password/page.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ForbiddenError } from '@/domain/errors';
import { GetUser } from '@/application/server';
import { Metadata } from 'next';
import { redirect } from 'next/navigation';
Expand All @@ -8,6 +9,7 @@ import {
import { Symbols } from '@/config/symbols';
import { serverContainer } from '@/server-injection';
import { User } from '@/domain/entities';

export const metadata: Metadata = {
title: 'Atur Ulang Kata Sandi',
};
Expand All @@ -27,7 +29,9 @@ export default async function ResetPasswordPage({ searchParams }: Props) {
try {
user = await getUser.execute();
} catch (error) {
// Do nothing
if (error instanceof ForbiddenError && error.message.includes('not verified')) {
redirect(`/verify-email?callback_url=${searchParams.callback_url}`);
}
}

if (user) {
Expand Down

0 comments on commit cfbd29c

Please sign in to comment.