You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
From other discussions. I'm not sure which one is right but I've tried both with the same result.
here is my pages/api/auth/[...nextauth].tsx:
const prisma = new PrismaClient();
const authHandler: NextApiHandler = (req, res) => NextAuth(req, res, options);
export default authHandler;
const options = {
providers: [
EmailProvider({
server: {
host: process.env.SMTP_HOST,
port: Number(process.env.SMTP_PORT),
auth: {
user: process.env.SMTP_USER,
pass: process.env.SMTP_PASSWORD,
},
},
from: process.env.SMTP_FROM,
}),
CredentialsProvider({
name: "Credentials",
credentials: {
username: { label: "Username", type: "text", placeholder: "jsmith" },
password: { label: "Password", type: "password" }
},
async authorize(credentials, req) {
const user = await prisma.user.findFirst({
where: {
username: credentials?.username, password: credentials?.password
}
})
if (user) {
// Any object returned will be saved in `user` property of the JWT
return user
} else {
// If you return null then an error will be displayed advising the user to check their details.
return null
// You can also Reject this callback with an Error thus the user will be sent to the error page with the error message as a query parameter
}
}
})
],
adapter: PrismaAdapter(prisma),
secret: process.env.SECRET,
session: {
strategy: 'jwt',
},
callbacks : {
async jwt({ token, user, account, profile }) {
// Persist the OAuth access_token and or the user id to the token right after signin
if (account) {
token.accessToken = account.access_token
// token.id = profile.id
}
if(user)
token.user = user
return token
},
async session({ session, token, user }) {
// Send properties to the client, like an access_token and user id from a provider.
session.accessToken = token.accessToken
session.user.id = token.id
session.user.username = user.username
return session
}
}
};
How do I fix this? and side question, How do I add the returned user to the token? And how do I access the token on other pages?
Also any critique is welcome, I pasted this together from many different sources... If anyone can point me to a solid tutorial that would be great. Thanks
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm getting instantly logged out because the cookie is expired:
Cookie “next-auth.session-token” has been rejected because it is already expired.
I have tried both
From other discussions. I'm not sure which one is right but I've tried both with the same result.
here is my pages/api/auth/[...nextauth].tsx:
How do I fix this? and side question, How do I add the returned user to the token? And how do I access the token on other pages?
Also any critique is welcome, I pasted this together from many different sources... If anyone can point me to a solid tutorial that would be great. Thanks
Beta Was this translation helpful? Give feedback.
All reactions