Fixed login step
This commit is contained in:
parent
9c4df176b9
commit
237a44e87e
|
@ -6,9 +6,8 @@ import {domain} from './config'
|
|||
import Repository from './repository'
|
||||
import {DBEntity, User} from "./types";
|
||||
|
||||
export class SessionAlreadyValidatedError extends Error {
|
||||
export class SessionAlreadyValidatedError extends Error {}
|
||||
|
||||
}
|
||||
const generateHash = () => randomstring({
|
||||
length: 48,
|
||||
letters: true,
|
||||
|
@ -68,7 +67,7 @@ export default class SessionManager {
|
|||
await sendEmail({
|
||||
to: user.email,
|
||||
from: `signin@${domain}`,
|
||||
text: `Follow this link to start a session: https://${domain}/signin?hash=${invite.hash}&email=${user.email}`,
|
||||
text: `Follow this link to start a session: https://${domain}/login/${invite.hash}`,
|
||||
subject: 'Invitation for session'
|
||||
})
|
||||
resolve(invite)
|
||||
|
|
|
@ -5,24 +5,39 @@ import {Link, match} from "react-router-dom";
|
|||
interface Props {
|
||||
match: match<{hash: string, email: string}>
|
||||
}
|
||||
|
||||
type LoginStatus = 'success' | 'error' | 'failure' | 'loading'
|
||||
interface State {
|
||||
loginStatus: 'success' | 'error' | 'failure' | 'loading'
|
||||
loginStatus: LoginStatus
|
||||
}
|
||||
|
||||
const responseCodeToLoginStatus = {
|
||||
200: 'success',
|
||||
403: 'failure',
|
||||
500: 'error'
|
||||
}
|
||||
class InitiateSession extends React.Component<Props, State> {
|
||||
constructor(props: Props) {
|
||||
super(props);
|
||||
this.state = {loginStatus: 'loading'}
|
||||
}
|
||||
|
||||
async componentDidMount() {
|
||||
const { hash } = this.props.match.params
|
||||
this.setState({loginStatus: 'loading'})
|
||||
const response = await axios.post('/api/signin', {
|
||||
hash,
|
||||
})
|
||||
const loginStatus = responseCodeToLoginStatus[response.status] || 'error';
|
||||
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) {
|
||||
loginStatus = 'error';
|
||||
}
|
||||
if (loginStatus === undefined) {
|
||||
throw new Error('Could not determine login statue')
|
||||
}
|
||||
this.setState({loginStatus})
|
||||
}
|
||||
|
||||
|
@ -33,7 +48,7 @@ class InitiateSession extends React.Component<Props, State> {
|
|||
this.state.loginStatus === 'loading' && <div>Please wait ...</div>
|
||||
}
|
||||
{
|
||||
this.state.loginStatus === 'success' && <div>You are now logged in. <Link to="/events/create">Create your event</Link></div>
|
||||
this.state.loginStatus === 'success' && <div>You are now logged in. <Link to="/events/create">Create an event</Link></div>
|
||||
}
|
||||
{
|
||||
this.state.loginStatus === 'failure' && <div>Could not log you in</div>
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
"object-literal-sort-keys":false,
|
||||
"no-console": false,
|
||||
"interface-name" : false,
|
||||
"no-empty-interface" : false
|
||||
"no-empty-interface" : false,
|
||||
"max-classes-per-file" : false
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue