Created
August 1, 2021 03:32
-
-
Save hoangsetup/5468d85bacc5b2655a0b29df74c3b133 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import express from 'express'; | |
import cognitoUserPoolHelper from './cognito.user.pool.helper'; | |
interface IUserController { | |
signUp: express.Handler, | |
signIn: express.Handler, | |
confirmSignUp: express.Handler, | |
getProfile: express.Handler, | |
} | |
const userController: IUserController = { | |
signUp: async (req, res) => { | |
try { | |
const { password, email } = req.body; | |
const result = await cognitoUserPoolHelper.signUp({ email, password }); | |
res.json({ message: `${result} is created.` }); | |
} catch (err) { | |
res.status(500).json({ message: err.message }); | |
} | |
}, | |
confirmSignUp: async (req, res) => { | |
try { | |
const { email, code } = req.body; | |
const result = await cognitoUserPoolHelper.confirmSignUp({ email, code }); | |
res.json({ message: result }); | |
} catch (err) { | |
res.status(500).json({ message: err.message }); | |
} | |
}, | |
signIn: async (req, res) => { | |
try { | |
const { email, password } = req.body; | |
const result = await cognitoUserPoolHelper.signIn({ email, password }); | |
res.json(result); | |
} catch (err) { | |
res.status(500).json({ message: err.message }); | |
} | |
}, | |
getProfile: (req, res) => { | |
res.json({}); | |
}, | |
}; | |
export default userController; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment