Skip to content

Commit

Permalink
[Feat] Auth redirects to client
Browse files Browse the repository at this point in the history
Made the API login endpoints redirect to the client application.
References #17, #21.
  • Loading branch information
angel-penchev committed Oct 23, 2021
1 parent 2622df4 commit 7e73d8c
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 19 deletions.
2 changes: 2 additions & 0 deletions server/.env.template
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
APP_PORT=
APP_PREFIX=

CLIENT_ROOT=

DATABASE_DRIVER=
DATABASE_HOST=
DATABASE_PORT=
Expand Down
15 changes: 12 additions & 3 deletions server/src/auth/controllers/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
HttpCode,
HttpStatus,
Post,
Redirect,
Req,
Res,
UseGuards,
Expand All @@ -16,10 +17,12 @@ import {
ApiCookieAuth,
ApiCreatedResponse,
ApiForbiddenResponse,
ApiMovedPermanentlyResponse,
ApiOkResponse,
ApiUnauthorizedResponse,
} from '@nestjs/swagger';
import { Request, Response } from 'express';
import { configObject } from 'src/configuration';
import AuthError from '../errors/auth.error';
import { AuthErrorCode } from '../errors/auth.error.code';
import { AuthDiscordGuard } from '../guards/auth.discord.guard';
Expand Down Expand Up @@ -66,24 +69,30 @@ export class AuthController {

@Get('/login/google')
@HttpCode(HttpStatus.OK)
@Redirect(configObject.client.root, HttpStatus.MOVED_PERMANENTLY)
@UseGuards(AuthGoogleGuard)
@ApiOkResponse({ description: 'User logged in.' })
@ApiOkResponse({ description: 'Google OAuth screen.' })
@ApiMovedPermanentlyResponse({ description: 'User logged in.' })
getGoogleLogin() {
return 'OK';
}

@Get('/login/discord')
@HttpCode(HttpStatus.OK)
@Redirect(configObject.client.root, HttpStatus.MOVED_PERMANENTLY)
@UseGuards(AuthDiscordGuard)
@ApiOkResponse({ description: 'User logged in.' })
@ApiOkResponse({ description: 'Discord OAuth screen.' })
@ApiMovedPermanentlyResponse({ description: 'User logged in.' })
getDiscordLogin() {
return 'OK';
}

@Get('/login/github')
@HttpCode(HttpStatus.OK)
@Redirect(configObject.client.root, HttpStatus.MOVED_PERMANENTLY)
@UseGuards(AuthGithubGuard)
@ApiOkResponse({ description: 'User logged in.' })
@ApiOkResponse({ description: 'GitHub OAuth screen.' })
@ApiMovedPermanentlyResponse({ description: 'User logged in.' })
getGithubLogin() {
return 'OK';
}
Expand Down
3 changes: 3 additions & 0 deletions server/src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ const configuration = () => ({
port: parseInt(process.env.APP_PORT || '3000'),
prefix: process.env.APP_PREFIX || 'api',
},
client: {
root: process.env.CLIENT_ROOT,
},
database: {
type: process.env.DATABASE_DRIVER,
host: process.env.DATABASE_HOST,
Expand Down
34 changes: 18 additions & 16 deletions server/types/enviourment.d.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,37 @@
declare namespace NodeJS {
export interface ProcessEnv {
NODE_ENV: 'development' | 'production';
NODE_ENV?: 'development' | 'production';

APP_PORT?: string;
APP_PREFIX?: string;

CLIENT_ROOT?: string;

DATABASE_DRIVER?: string;
DATABASE_HOST?: string;
DATABASE_PORT?: string;
DATABASE_USERNAME?: string;
DATABASE_PASSWORD?: string;
DATABASE_NAME?: string;

SESSION_SECRET: string;
SESSION_SECRET?: string;

GOOGLE_CLIENT_ID: string;
GOOGLE_CLIENT_SECRET: string;
GOOGLE_CALLBACK_API: string;
GOOGLE_CLIENT_ID?: string;
GOOGLE_CLIENT_SECRET?: string;
GOOGLE_CALLBACK_API?: string;

DISCORD_CLIENT_ID: string;
DISCORD_CLIENT_SECRET: string;
DISCORD_CALLBACK_API: string;
DISCORD_CLIENT_ID?: string;
DISCORD_CLIENT_SECRET?: string;
DISCORD_CALLBACK_API?: string;

GITHUB_CLIENT_ID: string;
GITHUB_CLIENT_SECRET: string;
GITHUB_CALLBACK_URL: string;
GITHUB_CLIENT_ID?: string;
GITHUB_CLIENT_SECRET?: string;
GITHUB_CALLBACK_URL?: string;

AWS_REGION: string;
AWS_ACCESS_KEY_ID: string;
AWS_SECRET_ACCESS_KEY: string;
AWS_CODE_SNIPPETS_S3_BUCKET: string;
AWS_RECORDINGS_S3_BUCKET: string;
AWS_REGION?: string;
AWS_ACCESS_KEY_ID?: string;
AWS_SECRET_ACCESS_KEY?: string;
AWS_CODE_SNIPPETS_S3_BUCKET?: string;
AWS_RECORDINGS_S3_BUCKET?: string;
}
}

0 comments on commit 7e73d8c

Please sign in to comment.