Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/actions/auth/oauth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ import { revalidatePath } from 'next/cache';
// =============================== Oauth Login ===============================
export async function oAuthLogin(provider: string) {
let user = '/';
user = await signIn(provider, {
redirect: false,
});
try {
user = await signIn(provider, { redirect: false });
console.log('user', user);
} catch (error) {
console.log('error', error);
}
// console.log(user);

if (user) redirect(user);
}
Expand Down
19 changes: 18 additions & 1 deletion src/app/(auth)/error/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ enum Error {
Configuration = 'Configuration',
AccessDenied = 'AccessDenied',
Verification = 'Verification',
OAuthAccountNotLinked = 'OAuthAccountNotLinked',
Default = 'Default',
}

Expand All @@ -22,14 +23,30 @@ const errorMap = {
[Error.AccessDenied]: (
<div className='flex flex-col items-center justify-center gap-4'>
<h2 className='text-xl font-bold'>
Oauth Account is already linked to another account.
You are not authorized to access this page.
</h2>
<p>
Unique error code:{' '}
<code className='rounded-sm bg-slate-100 p-1 text-xs'>
AccessDenied
</code>
</p>
<Link className='text-blue-500' href='/'>
Go to Home
</Link>
</div>
),
[Error.OAuthAccountNotLinked]: (
<div className='flex flex-col items-center justify-center gap-4'>
<h2 className='text-xl font-bold'>
Oauth Account is already linked to another account.
</h2>
<p>
Unique error code:{' '}
<code className='rounded-sm bg-slate-100 p-1 text-xs'>
OAuthAccountNotLinked
</code>
</p>
<Link className='text-blue-500' href='/profile'>
Go to Profile
</Link>
Expand Down
4 changes: 2 additions & 2 deletions src/auth.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import NextAuth, { AuthError } from 'next-auth';
import { OAuthAccountNotLinked } from '@auth/core/errors';
// import { OAuthAccountNotLinked } from '@auth/core/errors';
import Google from 'next-auth/providers/google';
import Github from 'next-auth/providers/github';
import Credentials from 'next-auth/providers/credentials';
Expand Down Expand Up @@ -85,7 +85,7 @@ export const { handlers, signIn, signOut, auth } = NextAuth({
account?.providerAccountId as string,
);
if (existingUser) {
throw new OAuthAccountNotLinked('OAuth account is already linked');
return '/error?error=OAuthAccountNotLinked';
} else {
return true;
}
Expand Down