Re-implement authentication (#136)

* Remove hasura and hasura-auth

* Implement authentication
This commit is contained in:
Charles Bochet
2023-05-25 11:51:15 +02:00
committed by GitHub
parent 5d06398d2e
commit 80f9cc8797
21 changed files with 1937 additions and 11092 deletions

View File

@ -0,0 +1,27 @@
import { Controller, Get, Req, Res, UseGuards } from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
import { Request, Response } from 'express';
import { AuthService } from './services/auth.service';
import { Profile } from 'passport-google-oauth20';
@Controller('auth/google')
export class GoogleAuthController {
constructor(private authService: AuthService) {}
@Get()
@UseGuards(AuthGuard('google'))
async googleAuth(@Req() req) {}
@Get('redirect')
@UseGuards(AuthGuard('google'))
async googleAuthRedirect(@Req() req: Request, @Res() res: Response) {
const user = await this.authService.upsertUser(req.user as { firstName: string, lastName: string, email: string })
if (!user) {
return res.status(400).send('User not created');
}
const refreshToken = await this.authService.registerRefreshToken(user)
return res.redirect(this.authService.computeRedirectURI(refreshToken.refreshToken));
}
}