I want to render data in client side below from parse after signin from next auth using useSession
{ objectId: 'nttMcKIOQJ', username: 'fiik346', email: 'fiik346@gmail.com', createdAt: '2022-06-26T07:56:41.888Z', updatedAt: '2022-06-26T07:56:41.888Z', ACL: { '*': { read: true }, nttMcKIOQJ: { read: true, write: true } }, sessionToken: 'r:2f2c569be3b5120f3893834c2ace7b67' }
But it’s just render email
{"user": {"email":"fiik346@gmail.com"},"expires":"2022-07-26T09:01:41.163Z"} "authenticated"
This is my callbacks code
// /pages/api/auth/[...nextauth].js ... callbacks: { async session({ session, token, user }) { // Send properties to the client, like an access_token from a provider. return session }, async jwt({ token, user, account, profile, isNewUser }) { return token } }, ...
And client side code
import { useSession } from 'next-auth/react' import { getToken } from 'next-auth/jwt' export default function accountIndex() { const {data: session, status} = useSession() return ( <div> <h1>Account is {status}</h1> <pre className="overflow-auto"> {JSON.stringify(session)} <br/> {JSON.stringify(status)} </pre> </div> ) }
I don’t know how to change my callbacks code to display data from database
Advertisement
Answer
After a while and try harder, I was successful to render data. Just change callback code like below.
... callbacks: { async session({ session, token, user }) { // Send properties to the client, like an access_token from a provider. session.accessToken = token.accessToken session.user = token.data return session }, async jwt({ token, user, account, profile, isNewUser }) { if (user) { token.data = user } return token } }, ...