feat: fix
This commit is contained in:
parent
c6bd7825ce
commit
552e70bcf3
|
|
@ -6,8 +6,8 @@ import { LoginUserDto } from '@gitroom/nestjs-libraries/dtos/auth/login.user.dto
|
||||||
import { AuthService } from '@gitroom/backend/services/auth/auth.service';
|
import { AuthService } from '@gitroom/backend/services/auth/auth.service';
|
||||||
import { ForgotReturnPasswordDto } from '@gitroom/nestjs-libraries/dtos/auth/forgot-return.password.dto';
|
import { ForgotReturnPasswordDto } from '@gitroom/nestjs-libraries/dtos/auth/forgot-return.password.dto';
|
||||||
import { ForgotPasswordDto } from '@gitroom/nestjs-libraries/dtos/auth/forgot.password.dto';
|
import { ForgotPasswordDto } from '@gitroom/nestjs-libraries/dtos/auth/forgot.password.dto';
|
||||||
import { removeSubdomain } from '@gitroom/helpers/subdomain/subdomain.management';
|
|
||||||
import { ApiTags } from '@nestjs/swagger';
|
import { ApiTags } from '@nestjs/swagger';
|
||||||
|
import { getCookieUrlFromDomain } from '@gitroom/helpers/subdomain/subdomain.management';
|
||||||
|
|
||||||
@ApiTags('Auth')
|
@ApiTags('Auth')
|
||||||
@Controller('/auth')
|
@Controller('/auth')
|
||||||
|
|
@ -37,8 +37,7 @@ export class AuthController {
|
||||||
}
|
}
|
||||||
|
|
||||||
response.cookie('auth', jwt, {
|
response.cookie('auth', jwt, {
|
||||||
domain:
|
domain: getCookieUrlFromDomain(process.env.FRONTEND_URL!),
|
||||||
'.' + new URL(removeSubdomain(process.env.FRONTEND_URL!)).hostname,
|
|
||||||
secure: true,
|
secure: true,
|
||||||
httpOnly: true,
|
httpOnly: true,
|
||||||
sameSite: 'none',
|
sameSite: 'none',
|
||||||
|
|
@ -47,8 +46,7 @@ export class AuthController {
|
||||||
|
|
||||||
if (typeof addedOrg !== 'boolean' && addedOrg?.organizationId) {
|
if (typeof addedOrg !== 'boolean' && addedOrg?.organizationId) {
|
||||||
response.cookie('showorg', addedOrg.organizationId, {
|
response.cookie('showorg', addedOrg.organizationId, {
|
||||||
domain:
|
domain: getCookieUrlFromDomain(process.env.FRONTEND_URL!),
|
||||||
'.' + new URL(removeSubdomain(process.env.FRONTEND_URL!)).hostname,
|
|
||||||
secure: true,
|
secure: true,
|
||||||
httpOnly: true,
|
httpOnly: true,
|
||||||
sameSite: 'none',
|
sameSite: 'none',
|
||||||
|
|
@ -83,8 +81,7 @@ export class AuthController {
|
||||||
);
|
);
|
||||||
|
|
||||||
response.cookie('auth', jwt, {
|
response.cookie('auth', jwt, {
|
||||||
domain:
|
domain: getCookieUrlFromDomain(process.env.FRONTEND_URL!),
|
||||||
'.' + new URL(removeSubdomain(process.env.FRONTEND_URL!)).hostname,
|
|
||||||
secure: true,
|
secure: true,
|
||||||
httpOnly: true,
|
httpOnly: true,
|
||||||
sameSite: 'none',
|
sameSite: 'none',
|
||||||
|
|
@ -93,8 +90,7 @@ export class AuthController {
|
||||||
|
|
||||||
if (typeof addedOrg !== 'boolean' && addedOrg?.organizationId) {
|
if (typeof addedOrg !== 'boolean' && addedOrg?.organizationId) {
|
||||||
response.cookie('showorg', addedOrg.organizationId, {
|
response.cookie('showorg', addedOrg.organizationId, {
|
||||||
domain:
|
domain: getCookieUrlFromDomain(process.env.FRONTEND_URL!),
|
||||||
'.' + new URL(removeSubdomain(process.env.FRONTEND_URL!)).hostname,
|
|
||||||
secure: true,
|
secure: true,
|
||||||
httpOnly: true,
|
httpOnly: true,
|
||||||
sameSite: 'none',
|
sameSite: 'none',
|
||||||
|
|
@ -149,8 +145,7 @@ export class AuthController {
|
||||||
}
|
}
|
||||||
|
|
||||||
response.cookie('auth', activate, {
|
response.cookie('auth', activate, {
|
||||||
domain:
|
domain: getCookieUrlFromDomain(process.env.FRONTEND_URL!),
|
||||||
'.' + new URL(removeSubdomain(process.env.FRONTEND_URL!)).hostname,
|
|
||||||
secure: true,
|
secure: true,
|
||||||
httpOnly: true,
|
httpOnly: true,
|
||||||
sameSite: 'none',
|
sameSite: 'none',
|
||||||
|
|
@ -173,8 +168,7 @@ export class AuthController {
|
||||||
}
|
}
|
||||||
|
|
||||||
response.cookie('auth', jwt, {
|
response.cookie('auth', jwt, {
|
||||||
domain:
|
domain: getCookieUrlFromDomain(process.env.FRONTEND_URL!),
|
||||||
'.' + new URL(removeSubdomain(process.env.FRONTEND_URL!)).hostname,
|
|
||||||
secure: true,
|
secure: true,
|
||||||
httpOnly: true,
|
httpOnly: true,
|
||||||
sameSite: 'none',
|
sameSite: 'none',
|
||||||
|
|
|
||||||
|
|
@ -4,12 +4,12 @@ import { AuthService } from '@gitroom/helpers/auth/auth.service';
|
||||||
import { User } from '@prisma/client';
|
import { User } from '@prisma/client';
|
||||||
import { OrganizationService } from '@gitroom/nestjs-libraries/database/prisma/organizations/organization.service';
|
import { OrganizationService } from '@gitroom/nestjs-libraries/database/prisma/organizations/organization.service';
|
||||||
import { UsersService } from '@gitroom/nestjs-libraries/database/prisma/users/users.service';
|
import { UsersService } from '@gitroom/nestjs-libraries/database/prisma/users/users.service';
|
||||||
import { removeSubdomain } from '@gitroom/helpers/subdomain/subdomain.management';
|
import { getCookieUrlFromDomain } from '@gitroom/helpers/subdomain/subdomain.management';
|
||||||
import { HttpForbiddenException } from '@gitroom/nestjs-libraries/services/exception.filter';
|
import { HttpForbiddenException } from '@gitroom/nestjs-libraries/services/exception.filter';
|
||||||
|
|
||||||
export const removeAuth = (res: Response) => {
|
export const removeAuth = (res: Response) => {
|
||||||
res.cookie('auth', '', {
|
res.cookie('auth', '', {
|
||||||
domain: '.' + new URL(removeSubdomain(process.env.FRONTEND_URL!)).hostname,
|
domain: getCookieUrlFromDomain(process.env.FRONTEND_URL!),
|
||||||
secure: true,
|
secure: true,
|
||||||
httpOnly: true,
|
httpOnly: true,
|
||||||
sameSite: 'none',
|
sameSite: 'none',
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
import {allTwoLevelSubdomain} from "./all.two.level.subdomain";
|
import {allTwoLevelSubdomain} from "./all.two.level.subdomain";
|
||||||
|
const ipRegex = /^(https?:\/\/)?(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})(:\d+)?$/;
|
||||||
|
|
||||||
export function removeSubdomain(domain: string) {
|
export function removeSubdomain(domain: string) {
|
||||||
// Check if the domain is an IP address with optional port
|
// Check if the domain is an IP address with optional port
|
||||||
const ipRegex = /^(https?:\/\/)?(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})(:\d+)?$/;
|
|
||||||
if (ipRegex.test(domain)) {
|
if (ipRegex.test(domain)) {
|
||||||
return domain; // Return the original domain if it's an IP address
|
return domain; // Return the original domain if it's an IP address
|
||||||
}
|
}
|
||||||
|
|
@ -24,3 +24,14 @@ export function removeSubdomain(domain: string) {
|
||||||
// Return the last two parts for standard domains
|
// Return the last two parts for standard domains
|
||||||
return 'https://' + parts.slice(-2).join('.');
|
return 'https://' + parts.slice(-2).join('.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export function getCookieUrlFromDomain(domain: string) {
|
||||||
|
const url = removeSubdomain(domain);
|
||||||
|
const urlObj = new URL(url);
|
||||||
|
if (!ipRegex.test(domain)) {
|
||||||
|
return '.' + urlObj.hostname
|
||||||
|
}
|
||||||
|
|
||||||
|
return urlObj.hostname;
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue