Initial websockets getToken() returns null: next-auth + websockets :)
Hello!
So the way I am trying to authenticate websockets is like this:
And it works except for the initial requests. I wouldn't mind this (maybe I would since needless errors), but my problem is trying to use subscriptions: it just will prompt an error on the initial request and I can't think of a way to retry (retrying works for everything else). I would like to solve this initial null JWT token request problem as that would make everything work very nicely but I wouldn't mind making the subscriptions work either.
The way I am subscribing in my react component:
I would really appreciate some commentary/insight! Thank you for your time.
1 Reply
I also tried with handling auth with
const session = await getServerSession(req as any, res as any, authOptions);
however I run into the following error:
res.getHeader is not a function
Eventually I came with this which doesn't resolve anything as the token comes up null:
I got it working! I still get null sessions but now I do eventually get the session needed for a subscription to be possible! Working code is the following: