-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
44 additions
and
1 deletion.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,14 @@ | ||
import { Request, Response } from 'express' | ||
import { asyncHandler, successResponse } from '../utils' | ||
import { userService } from '../services' | ||
import { userService, authService } from '../services' | ||
|
||
export const register = asyncHandler(async (req: Request, res: Response) => { | ||
const user = await userService.createUser(req.body) | ||
successResponse(res, user, 201) | ||
}) | ||
|
||
export const login = asyncHandler(async (req: Request, res: Response) => { | ||
const { email, password } = req.body | ||
const user = await authService.loginUserWithEmailAndPassword(email, password) | ||
successResponse(res, user, 200) | ||
}) |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { userService } from '.' | ||
|
||
export const loginUserWithEmailAndPassword = async ( | ||
email: string, | ||
password: string, | ||
) => { | ||
const user = await userService.getUserByEmail(email) | ||
if (!user || user.password !== password) { | ||
throw new Error('password is incorrect') | ||
} | ||
return user | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * as userService from './user' | ||
export * as authService from './auth' |
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
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