I'm using next-auth for authentication and using the Credentials provider for logging in, my API returns an object containing an accessToken like this object:
{ "token" : "UzI1NiIsInR5cCI..." }
,
And I'm returning a similar object containing the token in authorize
property of CredentialsProviders
while my session
callback looks like this:
session({ session, token }) {
session.data = {
...session.user,
...token.user,
};
session.accessToken = token.accessToken;
return session;
}
And I use the useSession
hook in my client code like this:
const { data: session, status } = useSession();
to access the user's token to make API requests. Is this safe? Or is there another ways to achieve this? Keep in mind that this application is gonna be fully client side rendered despite the fact that I'm using Next.js, so keep that in mind. I'm asking this because most of the docs of Next.js is SSR focused.