[next-auth] Updating user model with new values after oauth signin

Maybe someone can give some pointers on this Let's say we have this flow 1. User tries to access an protected route 2. Is redirected to /login with an callbackUrl for the protected route and isSubmitting url query 3. Chooses to login with an oauth provider with the same callbackUrl as when they were redirected to /login After/or inbetween they login in with an oauth provider, I want to set a column in the User model ("role") to "some value" based on the "isSubmitting" url query Does anyone know how one could accomplished that? Right now, I've been thinking about creating another route where the user is redirected to after login, grab the callbackUrl, which then would look something like "/afterlogin?callbackUrl=url&isSubmitting=true", but if this is supposed to work, the callbackUrl on the "signIn" function would also look odd, as it would be a callbackUrl with a callbackUrl inside of it 😄 That seems a bit ehh? Any ideas?
3 Replies
nvegater
nvegater•16mo ago
I read your post 3 times and I couldn't understand what you're trying to accomplish. Maybe if you give more context or explain it in a simpler way? Maybe some Pseudo code ?
andersgee
andersgee•16mo ago
You can make a custom /signin page, next-auth has examples on it. You could for example grab the query and do things in the button onClick handler etc. Does that help?
chip
chip•16mo ago
I ended up finding a solution for it. I'll try re-explain the initial question, and the solution 😄 I am currently using a OAuth provider to let users sign up. The problem that I faced is that if a user tries to access a protected route, I need to redirect them to a login page with a few url queries to determine wether or not we should update the User model. I was hoping that next-auth provided some way of doing it by listening to events or such, but there is no way to get the url queries ofc. So my solution was to the following: User tried to access a protected page Get's redirected to /login?callbackUrl=url&isSubmitting=true The user then clicks on login with their desired oauth provider After a successful login, they are redirected to a /wizard route with the previous callbackUrl as a url query Then, if isSubmitting is true, I just update the User model, and redirect them back to the original page they were trying to access