feat: add session to AuthConfig

this handles the settings for the cookie session. The secret and the lifeTime of the cookie can be configured.

Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
Philip Molares 2021-09-04 17:46:58 +02:00 committed by David Mehren
parent 0ef0d1e111
commit 43242cccc9
No known key found for this signature in database
GPG key ID: 185982BA4C42B7C3
3 changed files with 24 additions and 0 deletions

View file

@ -9,11 +9,16 @@ import * as Joi from 'joi';
import { GitlabScope, GitlabVersion } from './gitlab.enum';
import {
buildErrorMessage,
parseOptionalInt,
replaceAuthErrorsWithEnvironmentVariables,
toArrayConfig,
} from './utils';
export interface AuthConfig {
session: {
secret: string;
lifeTime: number;
};
email: {
enableLogin: boolean;
enableRegister: boolean;
@ -101,6 +106,13 @@ export interface AuthConfig {
}
const authSchema = Joi.object({
session: {
secret: Joi.string().label('HD_SESSION_SECRET'),
lifeTime: Joi.number()
.default(100000)
.optional()
.label('HD_SESSION_LIFE_TIME'),
},
email: {
enableLogin: Joi.boolean()
.default(false)
@ -332,6 +344,10 @@ export default registerAs('authConfig', () => {
const authConfig = authSchema.validate(
{
session: {
secret: process.env.HD_SESSION_SECRET,
lifeTime: parseOptionalInt(process.env.HD_SESSION_LIFE_TIME),
},
email: {
enableLogin: process.env.HD_AUTH_EMAIL_ENABLE_LOGIN,
enableRegister: process.env.HD_AUTH_EMAIL_ENABLE_REGISTER,

View file

@ -6,6 +6,10 @@
import { registerAs } from '@nestjs/config';
export default registerAs('authConfig', () => ({
session: {
secret: 'my_secret',
lifeTime: 1209600000,
},
email: {
enableLogin: true,
enableRegister: true,

View file

@ -23,6 +23,10 @@ import { FrontendConfigService } from './frontend-config.service';
describe('FrontendConfigService', () => {
const domain = 'http://md.example.com';
const emptyAuthConfig: AuthConfig = {
session: {
secret: 'my-secret',
lifeTime: 1209600000,
},
email: {
enableLogin: false,
enableRegister: false,