jamesedmonston / graphql-authentication

GraphQL authentication for your headless Craft CMS applications.
Other
28 stars 22 forks source link

Persist Login across tabs and refresh #124

Closed sgtpenguin closed 1 year ago

sgtpenguin commented 1 year ago

This is more of a question than an issue so any guidance you can give would be greatly appreciated. I am attempting to use this plugin to create and authenticate users in a NextJs/React front end using Craft through GraphQL. I was able to successfully set up a login flow, but I'm getting lost with how to make that sign in persist through a refresh or new tab for reasonable period of time. Since the JWT is set to the default 30 minutes I would expect to stay logged in for that long. What am I missing in terms of implementation on my app to check if you're still logged in? I'm thinking that I'm supposed to check for the HttpOnly refresh token cookie and see if it's still good somehow, but I don't see any cookies set that look like they come from the plugin. I feel like I'm probably missing something very basic here.

Thank You!

jamesedmonston commented 1 year ago

@sgtpenguin hey, I'd probably recommend you take a look at the next-auth package. It handles most of the logic for you.

sgtpenguin commented 1 year ago

Thanks. I'm taking a look. Are you suggesting that I would use next-auth in conjunction with this plugin and craft, or as an alternative way to handle authentication alltogether?

jamesedmonston commented 1 year ago

@sgtpenguin yep, using next-auth in conjunction with this plugin. next-auth will handle the front-end side of your auth flow, and this plugin will handle the back-end authentication of users.

Googling nextjs jwt auth comes up with a load of articles that you might find useful, too!