T3 Stack NextAuth How to get Provider access token
I have one question I have T3 Stack, PrismaAdapter, GithubProvider How can I get access token from Github Provider?
I am trying to get github access token and preserve it
I am new to Next.js, NextAuth and T3 stack
if I use adapter does it bypass jwt ?
14 Replies
do I need to use
sessionToken
to look up the session in the database?
I want github accessToken
because I am going to use it to make github api callsThe access token should already be persisted into your DB being linked to the account.
You could write a protected query, and get the user and the accounts from there.
@SeanCassiere So I make a tRPC query request which provides me with
ctx
and I can use ctx
to cross reference user
?Yes, just remember that your probably DON'T want to pass the access_token back to the frontend for security.
You can retrieve the access token from Account table in the DB using the ctx -> session -> user -> id as reference, and then perform your action in the backend itself.
Also, make sure that the access_token has the correct scopes, since the default one if just for identity, and doesn't have persmissions for much else.
btw where should I put all thje prisma queries in the t3 stack ?
and Object destructing doesn't work well with typescript
That would be a bit more project specific.
You could add them directly into your tRPC queries/mutations, or abstract them into separate functions, or something other class based stuff.
I'd recommend put them as close as possible to where you are calling them from, till it is no longer viable.
I'm currently, spreading across a few files, since I know I'll be adding additional stuff in the future. But, it really is up to you.
What I'm doing ->
https://github.com/SeanCassiere/next-discord-clone/blob/master/src/server/router/server.ts#L30
https://github.com/SeanCassiere/next-discord-clone/blob/master/src/server/functions/server/create-new-server-by-user.ts
https://github.com/SeanCassiere/next-discord-clone/blob/master/src/server/services/Server.ts#L30
GitHub
next-discord-clone/create-new-server-by-user.ts at master · SeanCas...
(WIP) - A Discord clone with the T3 Stack. Contribute to SeanCassiere/next-discord-clone development by creating an account on GitHub.
GitHub
next-discord-clone/server.ts at master · SeanCassiere/next-discord-...
(WIP) - A Discord clone with the T3 Stack. Contribute to SeanCassiere/next-discord-clone development by creating an account on GitHub.
GitHub
next-discord-clone/Server.ts at master · SeanCassiere/next-discord-...
(WIP) - A Discord clone with the T3 Stack. Contribute to SeanCassiere/next-discord-clone development by creating an account on GitHub.
thanks a lot
btw do you use typing with prisma results
Do you mean how I get the types from a Prisma query?
for example
I have this
but whenever I try to destructure
i get type error
or should I just omit type when I use prisma queries
Could you try this
I'll be honest, I never use the select option and so types are never an issue there.
yeah that worked
thanks
Cool stuff
Happy building
thanks a lot I learned a lot from you today