Next.js Discord

Discord Forum

How to fire a client side event on sign-in with nextAuth?

Unanswered
Barbary Lion posted this in #help-forum
Open in Discord
Avatar
Barbary LionOP
I want to fire an event when a user signs in on the client side. Currently i can do it for new users cause they land on a welcome page. When a user signs in normally I increment user.logins on the server side and take them to their dashboard. Is there a good way to know if it's a new sign so i can fire a client side event?

11 Replies

Avatar
linesofcode
Cookies
Set a cookie if it’s a new sign in, then check for this cookie
You have access to req object in next auth
Also you can use middleware for that redirect after doing the cookie check
Avatar
Barbary LionOP
interesting, thank you @linesofcode
can you explain the middleware approach?
why do i want to redirect?
Avatar
linesofcode
if you want to show a differnt page for example for the first signed in users
vs users who have already signed in multiple times
Avatar
Barbary LionOP
for first signed in users this isn't needed
nextAuth config has a pages :{ newUser: path }