first commit
This commit is contained in:
commit
b7b0f253ce
85 files changed
+7560
No files matched your search
+29
@@ -0,0 +1,29 @@
|
||||
import NextAuth, { type DefaultSession } from "next-auth";
|
||||
import authConfig from "./auth.config";
|
||||
import { prisma } from "@/lib/db";
|
||||
|
||||
declare module "next-auth" {
|
||||
interface Session {
|
||||
user: { id: string } & DefaultSession["user"];
|
||||
}
|
||||
}
|
||||
|
||||
export const { handlers, auth, signIn, signOut } = NextAuth({
|
||||
...authConfig,
|
||||
callbacks: {
|
||||
...authConfig.callbacks,
|
||||
async jwt({ token, user, account }) {
|
||||
// Vid inloggning: koppla Authentik-kontot till en användare i databasen.
|
||||
if (account && user) {
|
||||
const externalId = `${account.provider}:${account.providerAccountId}`;
|
||||
const dbUser = await prisma.user.upsert({
|
||||
where: { externalId },
|
||||
update: { name: user.name ?? undefined, email: user.email ?? undefined },
|
||||
create: { externalId, name: user.name ?? null, email: user.email ?? null },
|
||||
});
|
||||
token.uid = dbUser.id;
|
||||
}
|
||||
return token;
|
||||
},
|
||||
},
|
||||
});
|
||||
Reference in new issue
Block a user