#NextAuth cannot read sessionToken

3 messages · Page 1 of 1 (latest)

hollow gazelle
#

I am trying to create a signin with google with next auth but I always receive cannot read sessionToken and actually when I debug I can see that google has sent me the response , i am using custom functions because i am using a separated backend and i cannot use an adapters

import api from "@/eden"; import { AuthOptions, DefaultSession } from "next-auth"; import GoogleProvider from "next-auth/providers/google"; import crypto from "crypto"; declare module "next-auth" { interface Session extends DefaultSession { user: User & DefaultSession["user"]; status: string; sessionToken?: string; } interface User { id: string; email: string; } } const authOptions: AuthOptions = { providers: [ GoogleProvider({ clientId: process.env.GOOGLE_CLIENT_ID!, clientSecret: process.env.GOOGLE_CLIENT_SECRET!, }), ], callbacks: { async redirect({ baseUrl }) { return baseUrl; }, async session({ session, token }) { if (session.user) { session.user.id = token.id as string; session.sessionToken = token.sessionToken as string; } return session; }, async jwt({ token, user }) { if (user) { token.id = user.id; token.sessionToken = crypto.randomUUID().toString(); } return token; }, }, session: { strategy: "database", maxAge: 6 * 30 * 24 * 60 * 60, }, events: { async signIn({ user }) { const sessionToken = crypto.randomUUID().toString(); const expires = new Date(Date.now() + 6 * 30 * 24 * 60 * 60 * 1000); await api.auth.session.post({ sessionToken, userId: user.id, expires: expires.toISOString(), }); }, async signOut({ token }) { const sessionToken = token?.sessionToken as string; if (!sessionToken) { return; } await api.auth.session.delete({ sessionToken }); }, }, }; export { authOptions };

grand cryptBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

hollow gazelle
#

fixed the issue by changing strategy to jwt instead of database