-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth.ts
More file actions
39 lines (36 loc) · 1.05 KB
/
auth.ts
File metadata and controls
39 lines (36 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { getUserWithCompany } from "@/actions/user.actions";
import prisma from "@/prisma/prisma";
import { PrismaAdapter } from "@auth/prisma-adapter";
import NextAuth from "next-auth";
import { Adapter } from "next-auth/adapters";
import Google from "next-auth/providers/google";
import LinkedIn from "next-auth/providers/linkedin";
export const { handlers, signIn, signOut, auth } = NextAuth({
trustHost: true,
adapter: PrismaAdapter(prisma) as Adapter,
providers: [
Google({ allowDangerousEmailAccountLinking: true }),
LinkedIn({ allowDangerousEmailAccountLinking: true }),
],
callbacks: {
session: async ({ session, user }) => {
const { success, user: dbUser } = await getUserWithCompany(user.id);
if (success && dbUser) {
return {
...session,
user: {
...session.user,
id: user.id,
company: dbUser.company,
},
};
}
return session;
},
},
pages: {
signIn: "/login",
error: "/error",
newUser: "/app/onboarding",
},
});