Skip to content

Commit

Permalink
Merge pull request #72 from SAMAHAN-Systems-Development/fix/get-session
Browse files Browse the repository at this point in the history
Fix/get session
  • Loading branch information
SaaammmyyyS authored Oct 27, 2024
2 parents 7b5871e + 30356ac commit 211c523
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/auth/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,21 @@ export class AuthController {
}
}

@Post('logout')
async logout(@Response() res: Res) {
try {
await this.authService.signOut();
return res.status(HttpStatus.OK).json({ message: 'Logout successful' });
} catch (error) {
return res
.status(HttpStatus.INTERNAL_SERVER_ERROR)
.json({ message: error.message || 'Failed to logout' });
}
}

@Get('user')
async getUser() {
const user = await this.supabaseService.getCurrentUser();
const user = await this.supabaseService.getCurrentSession();
return user;
}
}
5 changes: 5 additions & 0 deletions src/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ export class AuthService {
return;
}

async signOut() {
await this.supabaseService.signOutSupabaseUser();
return;
}

async getUserInfoBySupabaseUserId(
supabaseUserId: string,
): Promise<{ email: string; userType: string }> {
Expand Down
8 changes: 8 additions & 0 deletions supabase/supabase.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ export class SupabaseService {
return user;
}

async getCurrentSession() {
const { data, error } = await this.supabase.auth.getSession();
if (error) {
throw new HttpException('Invalid Credentials', HttpStatus.FORBIDDEN);
}
return data;
}

async createSupabaseUser(email: string, password: string): Promise<any> {
const { data, error } = await this.supabase.auth.signUp({
email,
Expand Down

0 comments on commit 211c523

Please sign in to comment.