Next.js Discord

Discord Forum

Using getToken() serverside returns undefined if token not set inside userObject???

Answered
Capelin posted this in #help-forum
Open in Discord
CapelinOP
How does one get the JWT token with "getToken()" from next-auth/jwt without exposing the JWT inside the user object using the credentials provider?

The following code works:
"insert custom AWS credentials logic that returns a response"
->
if (response.AuthenticationResult) {
const user = {
token: response.AuthenticationResult.AccessToken,
};
return user;
} else {
throw new Error("Authentication failed");
}



The following code does not work:
if (response.AuthenticationResult) {

const user = {
};

return user;
}

Explicitly setting token inside the user object is not specified as a requirement to use GetToken(). I don't understand why this behavior occurs?
Answered by Capelin
I missed that I set the token in the session callback. This has been solved
View full answer

1 Reply

CapelinOP
I missed that I set the token in the session callback. This has been solved
Answer