Skip to content

Instantly share code, notes, and snippets.

@morgondag
Created September 13, 2016 19:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save morgondag/348d1905f7fb6f05a896ce829cef8ee6 to your computer and use it in GitHub Desktop.
Save morgondag/348d1905f7fb6f05a896ce829cef8ee6 to your computer and use it in GitHub Desktop.
basic auth example
import React, { Component } from 'react'
import { render } from 'react-dom'
import { browserHistory, Router, Route, Link, withRouter } from 'react-router'
import { checkAuth } from './utils/auth.jsx'
import App from './components/app.jsx'
import Dashboard from './components/dashboard.jsx'
import Register from './components/register.jsx'
import Forgot from './components/forgot.jsx'
import Pwd from './components/pwd.jsx'
import NoMatch from './components/nomatch.jsx'
const Auth = (nextState, replace) => {
return checkAuth().catch(()=>{
browserHistory.push('/');
})
}
window.addEventListener('DOMContentLoaded', ()=> {
render((
<Router history={browserHistory}>
<Route path="/" component={App}>
<Route path="dashboard" component={Dashboard} onEnter={Auth} />
</Route>
<Route path="register" component={Register} />
<Route path="forgot" component={Forgot} />
<Route path="pwd" component={Pwd} />
<Route path="*" component={NoMatch}/>
</Router>
), document.querySelector('section'))
}, false)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment