import axios from 'axios'; import * as React from 'react'; import {Link, match} from "react-router-dom"; interface Props { match: match<{hash: string, email: string}> } type LoginStatus = 'success' | 'error' | 'failure' | 'loading' interface State { loginStatus: LoginStatus } class InitiateSession extends React.Component { constructor(props: Props) { super(props); this.state = {loginStatus: 'loading'} } async componentDidMount() { const { hash } = this.props.match.params let loginStatus: LoginStatus = 'loading'; this.setState({loginStatus}) try { const response = await axios.post('/api/signin', { hash, }) if (response.status === 200) { loginStatus = 'success' } else if (response.status === 403) { loginStatus = 'failure' } else if (response.status === 401) { loginStatus = 'failure'; } } catch (e) { const err = e console.log('caught error', err) loginStatus = 'error'; } if (loginStatus === undefined) { throw new Error('Could not determine login statue') } this.setState({loginStatus}) } render() { return

Thanks for coming back, we will log you in now.

{ this.state.loginStatus === 'loading' &&
Please wait ...
} { this.state.loginStatus === 'success' &&
You are now logged in. Create an event
} { this.state.loginStatus === 'failure' &&
Could not log you in
}

Thanks for coming back, we will log you in now.

} } export default InitiateSession