How can I access the user ID in the api route? #982
-
Hi guys, My question: I want to access the current authenticated user that hits
But it doesn't contain the id. Just the name, email (but its null) - this is the one user i logged in with (through github). For example when a user hits /api/todo/new I want to create the todo and I want to store the user id or email into this todo. But right now I don't know why. Have I missed something in the docs? I use |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
I think you can do something like this const session = await getSession({ req });
const currentSession = await prisma.session.findUnique({
where: { accessToken:session.accessToken) },
});
const user = await prisma.user.findUnique({
where: { id: currentSession?.userId },
});
const userId = user?.id but I'm not sure if this is the optimal way. |
Beta Was this translation helpful? Give feedback.
-
In RFC you mentioned this prop is described as "OPTIONAL", |
Beta Was this translation helpful? Give feedback.
I think you can do something like this
but I'm not sure if this is the optimal way.