From 7db6fd78f429b9ee0d1342457d87c06e54710831 Mon Sep 17 00:00:00 2001 From: Yasamato Date: Mon, 9 Dec 2024 10:36:20 +0100 Subject: [PATCH] Use server side signIn/signOut --- auth.ts | 5 ++--- components/buttons/LoginOrOutButton.tsx | 3 ++- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/auth.ts b/auth.ts index c4d59241..e4d47ee8 100644 --- a/auth.ts +++ b/auth.ts @@ -15,7 +15,6 @@ export const authOptions: NextAuthConfig = { brandColor: '#0d6efd', logo: process.env.NEXT_PUBLIC_DOMAIN + '/icons/logo.png', }, - session: { strategy: "jwt" }, callbacks: { // we want to access the user id async session({ session, user }) { @@ -23,7 +22,7 @@ export const authOptions: NextAuthConfig = { const id = user.id.toString() session.user.uid = id - const userData = (await findOneTyped(Types.user, id)) as User + const userData = (await findOneTyped(Types.user, id)) as User | null // create user account if not found if (userData === null) { console.log( @@ -46,7 +45,7 @@ export const authOptions: NextAuthConfig = { session.user.accountType = AccountType.user } else { - session.user.accountType = userData.accountType + session.user.accountType = userData.accountType ?? AccountType.user } } else { console.warn('session call with no user provided') diff --git a/components/buttons/LoginOrOutButton.tsx b/components/buttons/LoginOrOutButton.tsx index f7193bdf..7bba8151 100644 --- a/components/buttons/LoginOrOutButton.tsx +++ b/components/buttons/LoginOrOutButton.tsx @@ -1,5 +1,6 @@ import { isLogin } from '../../lib/session' -import { signIn, signOut, useSession } from 'next-auth/react' +import { useSession } from 'next-auth/react' +import { signIn, signOut } from '../../auth' import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' import { FC } from 'react' import { faSignInAlt } from '@fortawesome/free-solid-svg-icons/faSignInAlt'