Skip to content

Instantly share code, notes, and snippets.

@RUJodan
Created June 8, 2017 19:03
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 RUJodan/db8ce50ad1cbedee9776ae266ff59c97 to your computer and use it in GitHub Desktop.
Save RUJodan/db8ce50ad1cbedee9776ae266ff59c97 to your computer and use it in GitHub Desktop.
import React from 'react';
export async function isLoggedIn() {
const response = await fetch('/isLoggedIn', {
credentials : 'include'
});
const authenticated = await response.json();
return authenticated.loggedIn;
}
export default class AuthComponent extends React.Component {
state = {
auth : false
}
componentWillMount = _ => {
this.authorize();
console.log("component will mount", this.state.auth)
}
authorize = async _ => {
const auth = await isLoggedIn();
this.setState({
auth : auth
});
}
render() {
console.log("component will render", this.state.auth)
return(
<div>{this.state.auth ? React.createElement(this.props.authRoute, {}) : React.createElement(this.props.authFallback, {})}</div>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment