Skip to content
Snippets Groups Projects
Commit d8f77d4c authored by Steve Reis's avatar Steve Reis
Browse files

feat(datashield): Add logout

parent 181a299d
No related branches found
No related tags found
No related merge requests found
...@@ -6,11 +6,15 @@ import { ...@@ -6,11 +6,15 @@ import {
} from '@nestjs/common'; } from '@nestjs/common';
import { ConfigService } from '@nestjs/config'; import { ConfigService } from '@nestjs/config';
import { Args, Mutation, Resolver } from '@nestjs/graphql'; import { Args, Mutation, Resolver } from '@nestjs/graphql';
import { Response } from 'express'; import { Response, Request } from 'express';
import { GQLRequest } from 'src/common/decorators/gql-request.decoractor';
import { GQLResponse } from '../common/decorators/gql-response.decoractor'; import { GQLResponse } from '../common/decorators/gql-response.decoractor';
import { parseToBoolean } from '../common/utilities'; import { parseToBoolean } from '../common/utilities';
import { ENGINE_SERVICE } from '../engine/engine.constants'; import {
import { IEngineService } from '../engine/engine.interfaces'; ENGINE_MODULE_OPTIONS,
ENGINE_SERVICE,
} from '../engine/engine.constants';
import { IEngineOptions, IEngineService } from '../engine/engine.interfaces';
import { User } from '../users/models/user.model'; import { User } from '../users/models/user.model';
import { authConstants } from './auth-constants'; import { authConstants } from './auth-constants';
import { AuthService } from './auth.service'; import { AuthService } from './auth.service';
...@@ -29,6 +33,8 @@ export class AuthResolver { ...@@ -29,6 +33,8 @@ export class AuthResolver {
constructor( constructor(
@Inject(ENGINE_SERVICE) private readonly engineService: IEngineService, @Inject(ENGINE_SERVICE) private readonly engineService: IEngineService,
@Inject(ENGINE_MODULE_OPTIONS)
private readonly engineOptions: IEngineOptions,
private readonly authService: AuthService, private readonly authService: AuthService,
private readonly configService: ConfigService, private readonly configService: ConfigService,
) {} ) {}
...@@ -68,11 +74,23 @@ export class AuthResolver { ...@@ -68,11 +74,23 @@ export class AuthResolver {
@Mutation(() => Boolean) @Mutation(() => Boolean)
@UseGuards(JwtAuthGuard) @UseGuards(JwtAuthGuard)
logout(@GQLResponse() res: Response, @CurrentUser() user: User): boolean { logout(
if (user) this.logger.verbose(`${user.username} logged out`); @GQLRequest() req: Request,
@GQLResponse() res: Response,
@CurrentUser() user: User,
): boolean {
if (user) {
this.logger.verbose(`${user.username} logged out`);
try {
this.engineService.logout?.(req);
} catch (e) {
this.logger.debug(
`Service ${this.engineOptions.type} produce an error when logging out ${user.username}`,
);
}
}
res.clearCookie(authConstants.cookie.name); res.clearCookie(authConstants.cookie.name);
this.engineService.logout?.();
return true; return true;
} }
......
...@@ -205,6 +205,21 @@ export default class DataShieldService implements IEngineService { ...@@ -205,6 +205,21 @@ export default class DataShieldService implements IEngineService {
throw new NotImplementedException(); throw new NotImplementedException();
} }
async logout(request: Request): Promise<void> {
const user = request.user as User;
const cookie = [`sid=${user.extraFields['sid']}`, `user=${user.id}`].join(
';',
);
const path = new URL('/logout', this.options.baseurl).href;
this.httpService.get(path, {
headers: {
cookie,
},
});
}
async editExperient( async editExperient(
id: string, id: string,
expriment: ExperimentEditInput, expriment: ExperimentEditInput,
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment