Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How would I implement an authentication workflow? #148

Closed
roderik opened this issue Oct 29, 2016 · 12 comments
Closed

How would I implement an authentication workflow? #148

roderik opened this issue Oct 29, 2016 · 12 comments

Comments

@roderik
Copy link

roderik commented Oct 29, 2016

I usually do a "onEnter" on React Router to check and redirect to a login page.

Running the check in getInitialProps? But that does not feel right...

@sedubois
Copy link
Contributor

React-Router v4 solves this by using the React component lifecycle directly (componentWillMount etc). I raised the same question here: #91 (comment)

@sedubois
Copy link
Contributor

Actually I correct that, it's solved like this: https://react-router.now.sh/auth-workflow

@nkzawa
Copy link
Contributor

nkzawa commented Oct 29, 2016

#25 would resolve this issue too, since you can have any auth logics on your server.

@rauchg
Copy link
Member

rauchg commented Oct 29, 2016

Also, to be perfectly clear, for most use cases you don't need #25. That'd be only necessary if you don't even want to ship the component code (not data) according to authentication rules.

We perform authentication on zeit.co by re-using an authenticate method in getInitialProps across all the pages that require authentication.

@rauchg
Copy link
Member

rauchg commented Oct 29, 2016

Logged as #153

@nkzawa
Copy link
Contributor

nkzawa commented Oct 29, 2016

@rauchg A problem is you can't properly redirect unauthorized requests.

@jaredpalmer
Copy link
Contributor

jaredpalmer commented Oct 31, 2016

@rauchg You store your sessions on api.zeit.co rather that on zeit.co correct?

@luisrudge
Copy link

@rauchg what you do when the user is not authenticated?

@bhurlow
Copy link

bhurlow commented Dec 12, 2016

@rauchg can you elaborate on how you manage authentication in getInitialProps?

This makes sense to me for client side auth – could store token in browser. What about for when pages are rendered server side? E.g. with a <Link/> tag

@luisrudge
Copy link

@bhurlow you'll probably need a cookie.

@bhurlow
Copy link

bhurlow commented Dec 12, 2016

@luisrudge I ended up having the backend API manage the cookie placement

@timneutkens
Copy link
Member

Closing in favor of #153

@lock lock bot locked as resolved and limited conversation to collaborators May 12, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants