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

Protect URLS #79

Closed
sstubbs opened this issue Jul 21, 2017 · 2 comments
Closed

Protect URLS #79

sstubbs opened this issue Jul 21, 2017 · 2 comments

Comments

@sstubbs
Copy link

sstubbs commented Jul 21, 2017

How do I protect urls like using react router uses onEnter?

@lfades
Copy link

lfades commented Jul 22, 2017

I don't think you can, but you can use express (or something similar) for that.

const app = next({dev: true})
const handle = routes.getRequestHandler(app)

app.prepare()
.then(() => {
  const server = express()

  server.get('*', (req, res, next) => {
    // do something else...
    next()
  })

  server.get('*', (req, res) => {
    return handle(req, res)
  })
})

@fridays
Copy link
Owner

fridays commented Jul 24, 2017

getInitialProps is usually a good place to do this, then it works on both server and client. Something like:

Account.getInitialProps = async () => {
  const user = await callYourApi('/authenticate')
  // Maybe send 401 error?
}

@fridays fridays closed this as completed Aug 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants