Michael
Michael
TTCTheo's Typesafe Cult
Created by Michael on 1/20/2024 in #questions
Next auth with role based access control and credentials provider
Does anyone know of a good github repo which shows how to use next auth with t3 and the credentials provider? I have been reading the docs and watching videos for days and can't seem to find anything that connects all of the pieces. I successfully set up role based access control with github and google but the credentials provider is a bit of a beast. I also successfully set up a register page which saves to the user to the db with an encrypted password (bcyrpt). However, trying to set up a custom signin page that displays github, google, and email/pw and then redirects the user to the dashboard when done and successfully invokes the session callback is tricky. Not quite sure how to do that yet.
4 replies
TTCTheo's Typesafe Cult
Created by Michael on 1/11/2024 in #questions
NextAuth and role based access control
Can someone explain to me how to modify the the auth.ts file in the server folder when you set up a boilerplate t3 app with next auth in order to enable role based access control? I have been using a profile() callback (https://authjs.dev/guides/basics/role-based-access-control) with a GitHubProvider but I get an error with my prisma schema.
GitHubProvider({
profile(profile) {
return {
...profile,
role: profile.role ?? "user",
id: profile.id.toString(),
image: profile.avatar_url,
}
},
clientId: process.env.GITHUB_ID as string,
clientSecret: process.env.GITHUB_SECRET as string,
}),
GitHubProvider({
profile(profile) {
return {
...profile,
role: profile.role ?? "user",
id: profile.id.toString(),
image: profile.avatar_url,
}
},
clientId: process.env.GITHUB_ID as string,
clientSecret: process.env.GITHUB_SECRET as string,
}),
I added this in my User model role String @default("user") but no luck. Would really appreciate some insight on how to do this.
6 replies