diff --git a/apps/api/src/auth/auth.controller.ts b/apps/api/src/auth/auth.controller.ts index 29b4b254d..8c0489b21 100644 --- a/apps/api/src/auth/auth.controller.ts +++ b/apps/api/src/auth/auth.controller.ts @@ -13,11 +13,11 @@ import { CreateUserDto } from '../user/model/user.dto'; @Controller('auth') export class AuthController { - constructor(private readonly authService: AuthService) { } + constructor(private readonly authService: AuthService) {} - @Post('signin') - sign(@Body() dto: SignDto) { - return this.authService.signIn(dto); + @Post('login') + login(@Body() dto: SignDto) { + return this.authService.login(dto); } @Post('signup') @@ -26,8 +26,8 @@ export class AuthController { } @UseGuards(AuthGuard) - @Get('test') - tets(@Request() req) { + @Get('userInfo') + userInfo(@Request() req) { return req.user; } } diff --git a/apps/api/src/auth/auth.service.ts b/apps/api/src/auth/auth.service.ts index 019b31e49..9ee801797 100644 --- a/apps/api/src/auth/auth.service.ts +++ b/apps/api/src/auth/auth.service.ts @@ -15,9 +15,9 @@ export class AuthService { constructor( private userService: UserService, private jwtService: JwtService, - ) { } + ) {} - async signIn(dto: SignDto) { + async login(dto: SignDto) { const user = await this.userService.findWithPhone(dto); if (!user) { throw new HttpException('User not exists', HttpStatus.BAD_REQUEST); @@ -26,9 +26,10 @@ export class AuthService { throw new UnauthorizedException(); } - const payload = { userId: user.id, username: user.name }; + const payload = { userId: user.id, username: user.name, phone: user.phone }; return { token: await this.jwtService.signAsync(payload), + user: payload, }; } diff --git a/apps/client/api/auth.ts b/apps/client/api/auth.ts index 67bacd36e..7d885c1f3 100644 --- a/apps/client/api/auth.ts +++ b/apps/client/api/auth.ts @@ -1,21 +1,28 @@ import { type ErrorVo, isError } from "./common"; -interface SignInDto { +interface LoginDto { phone: string; password: string; } -interface SignUpDto extends SignInDto { +export interface UserInfo { + userId: string; + username: string; + phone: string; +} + +interface SignUpDto extends LoginDto { name: string; } -interface SignInVo { +interface LoginVo { token: string; + user: UserInfo } -export async function signin(dto: SignInDto) { +export async function login(dto: LoginDto) { const message = useMessage(); - const { data } = await useFetchPlus("/auth/signin", { + const { data } = await useFetchPlus("/auth/login", { body: dto, method: "post", }); @@ -23,12 +30,12 @@ export async function signin(dto: SignInDto) { message.error(data.value.message); return; } - return data.value as SignInVo; + return data.value as LoginVo; } export async function signUp(dto: SignUpDto) { const message = useMessage(); - const { data } = await useFetchPlus("/auth/signup", { + const { data } = await useFetchPlus("/auth/signup", { body: dto, method: "post", }); @@ -36,5 +43,5 @@ export async function signUp(dto: SignUpDto) { message.error(data.value.message); return; } - return data.value as SignInVo; + return data.value as LoginVo; } diff --git a/apps/client/components/Navbar/index.vue b/apps/client/components/Navbar/index.vue index 30743e9ec..5d6b973ea 100644 --- a/apps/client/components/Navbar/index.vue +++ b/apps/client/components/Navbar/index.vue @@ -1,4 +1,8 @@