Next.js Discord

Discord Forum

window is not defined

Answered
Atlantic mackerel posted this in #help-forum
Open in Discord
Avatar
Atlantic mackerelOP
Hey guys, Im usingnext-auth and I want to redirect after login successful
So I tried this:
      async jwt({token, account}: any) {
            if (account) {
                token.accessToken = account.access_token;
                if (window !== undefined)
                    window.location.href = "motion://" + token.accessToken
                console.log("test" + token.accessToken)
            }
            return token;
        },


but the error said:

[NEXT]   message: 'window is not defined',
[NEXT]   stack: 'ReferenceError: window is not defined\n'


How can I redirect after login?
Answered by Jesse677
but still work
View full answer

6 Replies

Avatar
use useRouter
window will work in production
but in dev it will scream at you
Avatar
but still work
Answer
Avatar
Atlantic mackerelOP
oh, got it thankyou!!
Avatar
mark as solution if it works @Atlantic mackerel