add mobile email sign up endpoint

This commit is contained in:
Satindar Dhillon
2022-08-01 10:42:39 -07:00
parent 0178e4a137
commit c076dd0f72
2 changed files with 49 additions and 1 deletions

View File

@ -6,7 +6,10 @@ import {
createMobileSignInResponse,
createMobileEmailSignInResponse,
} from './sign_in'
import { createMobileSignUpResponse } from './sign_up'
import {
createMobileSignUpResponse,
createMobileEmailSignUpResponse,
} from './sign_up'
import { createMobileAccountCreationResponse } from './account_creation'
export function mobileAuthRouter() {
@ -24,6 +27,17 @@ export function mobileAuthRouter() {
res.status(payload.statusCode).json(payload.json)
})
router.post('/email-sign-up', async (req, res) => {
const { email, password, username, name } = req.body
const payload = await createMobileEmailSignUpResponse(
email,
password,
username,
name
)
res.status(payload.statusCode).json(payload.json)
})
router.post('/sign-up', async (req, res) => {
const { token, provider, name } = req.body
const payload = await createMobileSignUpResponse(token, provider, name)

View File

@ -9,6 +9,8 @@ import {
} from '../auth_types'
import { createPendingUserToken, suggestedUsername } from '../jwt_helpers'
import UserModel from '../../../datalayer/user'
import { hashPassword } from '../../../utils/auth'
import { createUser } from '../../../services/create_user'
export async function createMobileSignUpResponse(
token?: string,
@ -41,6 +43,38 @@ export async function createMobileSignUpResponse(
}
}
export async function createMobileEmailSignUpResponse(
email?: string,
password?: string,
username?: string,
name?: string
): Promise<JsonResponsePayload> {
try {
if (!email || !password || !username || !name) {
throw new Error('Missing username, password, name, or username')
}
const hashedPassword = await hashPassword(password)
await createUser({
email,
provider: 'EMAIL',
sourceUserId: email,
name,
username: username.toLowerCase(),
password: hashedPassword,
pendingConfirmation: true,
})
return {
statusCode: 200,
json: {},
}
} catch (e) {
return signUpFailedPayload
}
}
const signUpFailedPayload = {
statusCode: 403,
json: { errorCodes: ['AUTH_FAILED'] },