Closed cblberlin closed 1 month ago
Hi @cblberlin,
If I'm not mistaken getToken
gets the decrypted/decoded contents of the JWT, which you are then sending to fastapi, which tries to decode it again, which doesn't work because it already is.
Try directly copying the headers and cookies from your incoming request in your nextjs route handler, and sending those through to fastapi unmodified, I think that should work.
Also on the fastapi side, leave the cookie name default.
Let me know if that works!
Wouldn't it be more clear-cut to completely separate the frontend and backend? It seems a bit odd to use Next.js for handling authentificatioin while having part of the backend implemented with FastAPI
That is possible too of course! I started this project because I already had a frontend using nextauth and a backend using fastapi, if you're starting something new from scratch you could set it up however you like and may not need this.
yes me too, i've implemented the authentification part using auth.js on early stage but later when i cooperate with my colleague (who use fastapi as backend who has more experience on db query) we find out the Authorization part in API calls being hard (cause we don't know how to decode the cookies in python backend) that's why i found out your library, right now we decided to seperate the frontend and backend entirely (re-write whole authentification part) to make it well clear-cut...luckly it's just on early stage so we don't need to re-write the whole part but only design a well-structured OpenAPI docs
Hi,
i tried to decode the jwt token from
auth.js v5.0.0-beta.17
and nextjs 14 app router, i just keep getting Invalid padding bytes errorfirstly i install the package
fastapi-nextauth-jwt
then i extrat the token in an api router
then my fastapi is like this
and in the fastapi terminal i got
any idea how where do i get wrong?