Feature / Refactor to session based auth in backend #9
|
@ -1,14 +1,13 @@
|
|||
import { createParamDecorator, ExecutionContext } from '@nestjs/common';
|
||||
import { JwtPayloadWithRefreshToken } from 'src/modules/auth-module/models/types';
|
||||
//import { JwtPayloadWithRefreshToken } from 'src/modules/auth-module/models/types';
|
||||
|
||||
export const GetCurrentUser = createParamDecorator(
|
||||
(
|
||||
data: keyof JwtPayloadWithRefreshToken | undefined,
|
||||
context: ExecutionContext
|
||||
) => {
|
||||
const request = context.switchToHttp().getRequest();
|
||||
// export const GetCurrentUser = createParamDecorator(
|
||||
// (
|
||||
// data: keyof JwtPayloadWithRefreshToken | undefined,
|
||||
// context: ExecutionContext
|
||||
// ) => {
|
||||
// const request = context.switchToHttp().getRequest();
|
||||
|
||||
if (!data) return request.user;
|
||||
return request.user[data];
|
||||
}
|
||||
);
|
||||
// if (!data) return request.user;
|
||||
// return request.user[data];
|
||||
// }
|
||||
// );
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
export * from './get-user-id.decorator';
|
||||
export * from './get-user.decorator';
|
||||
// export * from './get-user.decorator';
|
||||
|
|
|
@ -1,2 +1,4 @@
|
|||
export * from './jwt-payload.type';
|
||||
export * from './jwt-payload-with-refresh-token.type';
|
||||
// export * from './jwt-payload-with-refresh-token.type';
|
||||
export * from './token-payload.type';
|
||||
export * from './tokens.type';
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
import { JwtPayload } from './jwt-payload.type';
|
||||
// import { JwtPayload } from './jwt-payload.type';
|
||||
|
||||
export type JwtPayloadWithRefreshToken = JwtPayload & { refresh_token: string };
|
||||
// export type JwtPayloadWithRefreshToken = JwtPayload & { refresh_token: string };
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
export type TokenPayload = {
|
||||
sub: string;
|
||||
email: string;
|
||||
iat: number;
|
||||
exp: number;
|
||||
};
|
|
@ -0,0 +1,4 @@
|
|||
export type Tokens = {
|
||||
access_token: string;
|
||||
refresh_token: string;
|
||||
};
|
|
@ -11,13 +11,11 @@ import {
|
|||
LoginResponseDto,
|
||||
UserCredentialsDto,
|
||||
} from '../models/dto';
|
||||
import { TokenPayload } from '../models/types';
|
||||
import { UserCredentialsRepository } from '../repositories/user-credentials.repository';
|
||||
|
||||
import { SessionService } from './session.service';
|
||||
import {
|
||||
TokenManagementService,
|
||||
TokenPayload,
|
||||
} from './token-management.service';
|
||||
import { TokenManagementService } from './token-management.service';
|
||||
|
||||
@Injectable()
|
||||
export class AuthService {
|
||||
|
|
|
@ -2,17 +2,7 @@ import { Injectable } from '@nestjs/common';
|
|||
import { ConfigService } from '@nestjs/config';
|
||||
import { JwtService } from '@nestjs/jwt';
|
||||
|
||||
type Tokens = {
|
||||
access_token: string;
|
||||
refresh_token: string;
|
||||
};
|
||||
|
||||
export type TokenPayload = {
|
||||
sub: string;
|
||||
email: string;
|
||||
iat: number;
|
||||
exp: number;
|
||||
};
|
||||
import { TokenPayload, Tokens } from '../models/types';
|
||||
|
||||
@Injectable()
|
||||
export class TokenManagementService {
|
||||
|
|
Loading…
Reference in New Issue