I have the GoogleProvider
working, and returning a valid session. But when I create a CredentialsProvider
it isn t working.
The credentials provider successfully creates a user in the database with graphql. And I m able to log the returned user at the bottom.
import { client } from @/src/graphql/apollo-client
import UserOperations from @/src/graphql/operations/user
import { CreateUserData, CreateUserInput } from @/src/util/types
import credentialsProvider from next-auth/providers/credentials
export default CredentialsProvider({
name: ,
credentials: {
email: { label: Username , type: text , placeholder: email },
password: { label: Password , type: password }
},
async authorize(credentials, req) {
const signUp = UserOperations.Mutations.signUp
const response = await client.mutate<CreateUserData, CreateUserInput>({
mutation: signUp,
variables: {
email: credentials?.email!,
password: credentials?.password!
}
})
const { data } = response
const user = data
console.log( the user data returned is , user)
if (user) {
return user
}
return null
}
})
I m using that provider along side a GoogleProvider
in [...nextauth].ts
import NextAuth from next-auth
import GoogleProvider from next-auth/providers/google
import { PrismaAdapter } from @next-auth/prisma-adapter
import { PrismaClient } from @prisma/client
import CredentialsProvider from ./providers/credentials
const prisma = new PrismaClient()
export default NextAuth({
adapter: PrismaAdapter(prisma),
providers: [
credentialsProvider, //the credentials provider from above
GoogleProvider({
clientId: process.env.GOOGLE_CLIENT_ID as string,
clientSecret: process.env.GOOGLE_CLIENT_SECRET as string
})
],
secret: process.env.JWT_SECRET,
callbacks: {
async session({ session, token, user }) {
//here the google provider returns values, but the credentials provider does not.
console.log( session , session, user , user)
return {
...session,
user: { ...session.user, ...user } // combine the session and db user
}
}
}
})
Inside of async session you can see I have another console log. When using the google provider I can log the session and user, but I m getting session:null and user:null with the credentials provider.
So I m not sure where session gets set with Credentials Provider or what other steps I may be missing.
Happy to provide any other files if they help, but I thought this would be simplest to start.
Help is much appreciated, thanks.
EDIT - It looks like someone was able to use credentials provider along side Prisma adapter here. I tried adding the encode/ decode token block that they used, but still no luck.
I may be confused about how JWT fits into the picture.