Skip to content

Commit 6252e2e

Browse files
Merge pull request #3 from patelvivekdev/v15
Fix error not showing
2 parents dafb841 + 60835e0 commit 6252e2e

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

src/actions/auth/oauth.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,13 @@ import { revalidatePath } from 'next/cache';
99
// =============================== Oauth Login ===============================
1010
export async function oAuthLogin(provider: string) {
1111
let user = '/';
12-
user = await signIn(provider, {
13-
redirect: false,
14-
});
12+
try {
13+
user = await signIn(provider, { redirect: false });
14+
console.log('user', user);
15+
} catch (error) {
16+
console.log('error', error);
17+
}
18+
// console.log(user);
1519

1620
if (user) redirect(user);
1721
}

src/app/(auth)/error/page.tsx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ enum Error {
88
Configuration = 'Configuration',
99
AccessDenied = 'AccessDenied',
1010
Verification = 'Verification',
11+
OAuthAccountNotLinked = 'OAuthAccountNotLinked',
1112
Default = 'Default',
1213
}
1314

@@ -22,14 +23,30 @@ const errorMap = {
2223
[Error.AccessDenied]: (
2324
<div className='flex flex-col items-center justify-center gap-4'>
2425
<h2 className='text-xl font-bold'>
25-
Oauth Account is already linked to another account.
26+
You are not authorized to access this page.
2627
</h2>
2728
<p>
2829
Unique error code:{' '}
2930
<code className='rounded-sm bg-slate-100 p-1 text-xs'>
3031
AccessDenied
3132
</code>
3233
</p>
34+
<Link className='text-blue-500' href='/'>
35+
Go to Home
36+
</Link>
37+
</div>
38+
),
39+
[Error.OAuthAccountNotLinked]: (
40+
<div className='flex flex-col items-center justify-center gap-4'>
41+
<h2 className='text-xl font-bold'>
42+
Oauth Account is already linked to another account.
43+
</h2>
44+
<p>
45+
Unique error code:{' '}
46+
<code className='rounded-sm bg-slate-100 p-1 text-xs'>
47+
OAuthAccountNotLinked
48+
</code>
49+
</p>
3350
<Link className='text-blue-500' href='/profile'>
3451
Go to Profile
3552
</Link>

src/auth.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import NextAuth, { AuthError } from 'next-auth';
2-
import { OAuthAccountNotLinked } from '@auth/core/errors';
2+
// import { OAuthAccountNotLinked } from '@auth/core/errors';
33
import Google from 'next-auth/providers/google';
44
import Github from 'next-auth/providers/github';
55
import Credentials from 'next-auth/providers/credentials';
@@ -85,7 +85,7 @@ export const { handlers, signIn, signOut, auth } = NextAuth({
8585
account?.providerAccountId as string,
8686
);
8787
if (existingUser) {
88-
throw new OAuthAccountNotLinked('OAuth account is already linked');
88+
return '/error?error=OAuthAccountNotLinked';
8989
} else {
9090
return true;
9191
}

0 commit comments

Comments
 (0)