-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add Google sign-in route on server
- Loading branch information
Showing
6 changed files
with
109 additions
and
11 deletions.
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
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,34 @@ | ||
import { Request, Response, Router } from 'express'; | ||
|
||
import { AuthService } from '@src/core/services/auth/auth.service'; | ||
|
||
import { GoogleSignInV1Response } from '@controller/http/auth/response/auth.v1.response'; | ||
import { methodNotAllowed } from '@controller/http/handler'; | ||
|
||
export class AuthV1Controller { | ||
constructor(private readonly service: AuthService) {} | ||
|
||
public routes = (): Router => { | ||
const router: Router = Router(); | ||
const googlePrefix = '/v1/google'; | ||
|
||
router | ||
.route(`${googlePrefix}/sign-in`) | ||
.get(this.googleSignIn) | ||
.all(methodNotAllowed); | ||
|
||
return router; | ||
}; | ||
|
||
public googleSignIn = async ( | ||
req: Request, | ||
res: Response<GoogleSignInV1Response> | ||
) => { | ||
const referrer = req.get('Referer') ?? req.get('Referrer') ?? null; | ||
const redirectUri = this.service.initiateGoogleSignIn( | ||
req.protocol, | ||
referrer | ||
); | ||
res.redirect(redirectUri); | ||
}; | ||
} |
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 @@ | ||
export interface GoogleSignInV1Response {} |
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,20 @@ | ||
import { Tspec } from 'tspec'; | ||
|
||
import { GoogleSignInV1Response } from '@controller/http/auth/response/auth.v1.response'; | ||
import { HttpErrorResponse } from '@controller/http/response'; | ||
|
||
export type AuthV1ApiSpec = Tspec.DefineApiSpec<{ | ||
basePath: '/api/v1/google'; | ||
tags: ['Auth']; | ||
paths: { | ||
'/sign-in': { | ||
get: { | ||
summary: 'Initiate google sign in'; | ||
responses: { | ||
302: GoogleSignInV1Response; | ||
default: HttpErrorResponse; | ||
}; | ||
}; | ||
}; | ||
}; | ||
}>; |
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