Post session handler
This commit is contained in:
parent
7ec93333cf
commit
1a485891c7
|
@ -18,6 +18,10 @@
|
|||
"source": "/api/signin",
|
||||
"function": "signin"
|
||||
},
|
||||
{
|
||||
"soure": "/api/session",
|
||||
"function": "postSession"
|
||||
},
|
||||
{
|
||||
"source": "/api/events",
|
||||
"function": "events"
|
||||
|
|
|
@ -78,7 +78,7 @@ export const signup = async (req: Request, res: Response) => {
|
|||
}
|
||||
}
|
||||
|
||||
const handleSignin = (async (req: Request, res: Response) => {
|
||||
const handleSignin = async (req: Request, res: Response) => {
|
||||
const params = parse(req.url, true).query
|
||||
const ip = req.ip.split('.').map(num => parseInt(num))
|
||||
|
||||
|
@ -102,7 +102,7 @@ const handleSignin = (async (req: Request, res: Response) => {
|
|||
// todo: invalidate session invite
|
||||
res.setHeader('set-cookie', `__session=${session.hash}; Secure;`)
|
||||
res.send(`Session initiated: ${JSON.stringify(session)}`)
|
||||
})
|
||||
}
|
||||
|
||||
export const signin = async (req: Request, res: Response) => {
|
||||
try {
|
||||
|
@ -115,3 +115,29 @@ export const signin = async (req: Request, res: Response) => {
|
|||
throw e
|
||||
}
|
||||
}
|
||||
|
||||
const handlePostSession = async (req: Request, res: Response) => {
|
||||
const { email } = req.body
|
||||
|
||||
console.log('Will request new session for email: ', email)
|
||||
const user = await userManager.getUser({email})
|
||||
if (!user) {
|
||||
res.status(404)
|
||||
res.send('Could not find user')
|
||||
return
|
||||
}
|
||||
await userManager.inviteUser(user)
|
||||
res.status(200)
|
||||
res.send('Invitation sent to email')
|
||||
}
|
||||
|
||||
export const postSession = async (req: Request, res: Response) => {
|
||||
try {
|
||||
await handlePostSession(req, res)
|
||||
} catch (e) {
|
||||
console.error('Error in request new session for existing user', e)
|
||||
res.send('Request session error')
|
||||
res.status(500)
|
||||
throw e
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,34 @@
|
|||
import axios from 'axios'
|
||||
import {Field, FieldProps, Form, Formik} from 'formik';
|
||||
import * as React from 'react';
|
||||
|
||||
const submitLogin = (loginRequest: LoginRequest) => {
|
||||
axios.post('/api/session', loginRequest)
|
||||
}
|
||||
|
||||
interface LoginRequest {
|
||||
email: string;
|
||||
}
|
||||
|
||||
const Login = () => (
|
||||
<div>
|
||||
<h1>Login</h1>
|
||||
<div>
|
||||
Please enter your email
|
||||
</div>
|
||||
<Formik onSubmit={submitLogin} initialValues={{email: ''}}>
|
||||
{
|
||||
() => (
|
||||
<Form>
|
||||
<Field name="email">
|
||||
{
|
||||
({ field }: FieldProps<string>) => <input {...field} />
|
||||
}
|
||||
</Field>
|
||||
</Form>
|
||||
)
|
||||
}
|
||||
</Formik>
|
||||
</div>
|
||||
)
|
||||
export default Login
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
"rules": {
|
||||
"member-access": false,
|
||||
"object-literal-sort-keys":false,
|
||||
"no-console": false
|
||||
"no-console": false,
|
||||
"interface-name" : false
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue