How to save users from next-auth after authentication?
Unanswered
let headache = null() posted this in #help-forum
Hi there,
Well today i was learning
So, for my app needs users to have different data which will be saving on mongodb so for that i need user's id or some of primary key ( PK ) how can i do that??
This above code is simple but doesn't accept any callbacks, i dont know why callbacks are required although i wanan learn but i dont have any ressources docs are outdated as everyone says!!
Thanks for your time.
Well today i was learning
next-auth
but i'm confused wheather how can i save user or should i save user on database for dynamic rendering
with unique user data
??So, for my app needs users to have different data which will be saving on mongodb so for that i need user's id or some of primary key ( PK ) how can i do that??
import NextAuth from "next-auth";
import GithubProvider from "next-auth/providers/github";
const handler = NextAuth({
providers: [
GithubProvider({
clientId: process.env.GITHUB_ID!,
clientSecret: process.env.GITHUB_SECRET!,
}),
],
});
export { handler as GET, handler as POST };
This above code is simple but doesn't accept any callbacks, i dont know why callbacks are required although i wanan learn but i dont have any ressources docs are outdated as everyone says!!
Thanks for your time.
8 Replies
@let headache = null() Hi there,
Well today i was learning `next-auth` but i'm confused wheather how can i save user or should i save user on database for `dynamic rendering` with `unique user data`??
So, for my app needs users to have different data which will be saving on mongodb so for that i need user's id or some of primary key ( PK ) how can i do that??
javascript
import NextAuth from "next-auth";
import GithubProvider from "next-auth/providers/github";
const handler = NextAuth({
providers: [
GithubProvider({
clientId: process.env.GITHUB_ID!,
clientSecret: process.env.GITHUB_SECRET!,
}),
],
});
export { handler as GET, handler as POST };
This above code is simple but doesn't accept any callbacks, i dont know why callbacks are required although i wanan learn but i dont have any ressources docs are outdated as everyone says!!
Thanks for your time.
you need to setup db adapters https://authjs.dev/getting-started/database
@Yi Lon Ma you need to setup db adapters https://authjs.dev/getting-started/database
Do people usually use clerk + next-auth?? or additional adapter?
@let headache = null() Do people usually use clerk + next-auth?? or additional adapter?
No, why would you use clerk with next auth?
You can use clerk to manage session
im looking for authenticate user suppose user has got a token can use /dashboard and who hasn't got token they can't so...?? how do we implement this system
@let headache = null() im looking for authenticate user suppose user has got a token can use /dashboard and who hasn't got token they can't so...?? how do we implement this system
Ehh, the simplest solution is to implement a role system to allow certain users to access the dashboard.
First set up the adapter with mongodb and add to your schema role with the roles you want to support and in next-auth you can extend the AdapterUser, Session, User and JWT (if you use it) and implement the role attribute that would contain the supported roles within your database to be able to access them with auth() or getSession() and in this way implement the validation of users who can access the dashboard.
If you want to save to DB, use clerk web hooks