Getting Github oauth callback url 'code' query param in next auth 5

90 Views Asked by At

I'm using next.js 14.1.0 and next-auth 5.0.0-beta.11. I have oauth login via github working. During the login process, github sends me a code as a query param to the callback url that I specified when I set up the github oauth app. I want to get this code so I can send to my django rest framework api to do some things with it.

In the network tab of the console I can see what I want to get:

http://localhost:3000/api/auth/callback/github?code=6c2b8421e341ed8caa2f

But I haven't been able to figure out how to grab this.

In my next auth set up, there is a dynamic route (api/auth/[...nextauth]) with a route.ts file containing export { GET, POST } from '@/auth'; The callback url would redirect the user logging in to here.... I don't know how to do this.

Any suggestions would be greatly appreciated.
Thanks.

I tried importing useSearchParams in my login component, which is a client component. But that doesn't work, i just get an undefined variable.

0

There are 0 best solutions below