Skip to content

Commit e3fe4c1

Browse files
committed
auth/me route created
1 parent 46d457c commit e3fe4c1

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

backend/src/auth/auth.controller.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import { Body, Controller, Post, Res } from '@nestjs/common';
1+
import { Body, Controller, Get, Post, Res, UseGuards } from '@nestjs/common';
22
import { AuthService } from './auth.service';
33
import { RegisterDto } from './dto/register.dto';
44
import { type Response } from 'express';
55
import { LoginDto } from './dto/login.dto';
6+
import { JwtAuthGuard } from './jwt-auth.guard';
7+
import type { User } from '@prisma/client';
68

79
@Controller('auth')
810
export class AuthController {
@@ -33,4 +35,10 @@ export class AuthController {
3335
res.clearCookie('jwt');
3436
return { message: 'Logged Out' };
3537
}
38+
39+
@Get('me')
40+
@UseGuards(JwtAuthGuard)
41+
getMe(user: User) {
42+
return user;
43+
}
3644
}

backend/src/auth/jwt-auth.guard.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { Injectable } from '@nestjs/common';
2+
import { AuthGuard } from '@nestjs/passport';
3+
4+
@Injectable()
5+
export class JwtAuthGuard extends AuthGuard('jwt') {}

0 commit comments

Comments
 (0)