I want to render data in client side below from parse after signin from next auth using useSession
JavaScript
x
10
10
1
{
2
objectId: 'nttMcKIOQJ',
3
username: 'fiik346',
4
email: 'fiik346@gmail.com',
5
createdAt: '2022-06-26T07:56:41.888Z',
6
updatedAt: '2022-06-26T07:56:41.888Z',
7
ACL: { '*': { read: true }, nttMcKIOQJ: { read: true, write: true } },
8
sessionToken: 'r:2f2c569be3b5120f3893834c2ace7b67'
9
}
10
But it’s just render email
JavaScript
1
3
1
{"user": {"email":"fiik346@gmail.com"},"expires":"2022-07-26T09:01:41.163Z"}
2
"authenticated"
3
This is my callbacks code
JavaScript
1
10
10
1
// /pages/api/auth/[...nextauth].js
2
3
4
callbacks: {
5
async session({ session, token, user }) { // Send properties to the client, like an access_token from a provider. return session
6
}, async jwt({ token, user, account, profile, isNewUser }) { return token
7
} },
8
9
10
And client side code
JavaScript
1
14
14
1
import { useSession } from 'next-auth/react'
2
import { getToken } from 'next-auth/jwt'
3
export default function accountIndex() {
4
const {data: session, status} = useSession() return ( <div>
5
<h1>Account is {status}</h1>
6
<pre className="overflow-auto">
7
{JSON.stringify(session)}
8
<br/>
9
{JSON.stringify(status)}
10
</pre>
11
</div>
12
)
13
}
14
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.
JavaScript
1
19
19
1
2
3
callbacks: {
4
async session({ session, token, user }) {
5
// Send properties to the client, like an access_token from a provider.
6
session.accessToken = token.accessToken
7
session.user = token.data
8
return session
9
},
10
async jwt({ token, user, account, profile, isNewUser }) {
11
if (user) {
12
token.data = user
13
}
14
return token
15
}
16
},
17
18
19