Skip to content

Commit

Permalink
Merge pull request #461 from VitNode/http_support
Browse files Browse the repository at this point in the history
feat(backend): Add support for http protocol
  • Loading branch information
aXenDeveloper authored Aug 21, 2024
2 parents b3a4539 + b90dc5a commit d5b01ac
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 18 deletions.
8 changes: 2 additions & 6 deletions packages/backend/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,7 @@ const replaceUrlToDomain = (url: string) => {
hostname = hostname.split('.').slice(1).join('.');
}

const domainParts = hostname.split('.');
if (domainParts.length > 1) {
domainParts.pop();
}

return domainParts.join('.');
return hostname;
};

const config = () => {
Expand All @@ -151,6 +146,7 @@ const config = () => {
port: process.env.PORT ? parseInt(process.env.PORT, 10) : 8080,
cookies: {
domain: replaceUrlToDomain(frontend_url.url),
secure: frontend_url.protocol === 'https:',
login_token: {
expiresIn: 3, // 3 days
expiresInRemember: 90, // 90 days
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ export class SignOutAdminSessionsService {
this.configService.getOrThrow('cookies.login_token.admin.name'),
{
httpOnly: true,
secure: true,
secure: !!this.configService.getOrThrow('cookies.secure'),
domain: this.configService.getOrThrow('cookies.domain'),
path: '/',
sameSite: 'none',
sameSite: this.configService.getOrThrow('cookies.secure')
? 'none'
: 'lax',
},
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,13 @@ export class InternalAuthorizationCoreSessionsService {
know_device_id,
{
httpOnly: true,
secure: true,
secure: !!this.configService.getOrThrow('cookies.secure'),
domain: this.configService.getOrThrow('cookies.domain'),
path: '/',
expires,
sameSite: 'none',
sameSite: this.configService.getOrThrow('cookies.secure')
? 'none'
: 'lax',
},
);

Expand Down
6 changes: 4 additions & 2 deletions packages/backend/src/core/sessions/sign_in/device.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,13 @@ export class DeviceSignInCoreSessionsService {
device.id,
{
httpOnly: true,
secure: true,
secure: !!this.configService.getOrThrow('cookies.secure'),
domain: this.configService.getOrThrow('cookies.domain'),
path: '/',
expires,
sameSite: 'none',
sameSite: this.configService.getOrThrow('cookies.secure')
? 'none'
: 'lax',
},
);

Expand Down
12 changes: 8 additions & 4 deletions packages/backend/src/core/sessions/sign_in/sign_in.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,13 @@ export class SignInCoreSessionsService {
login_token,
{
httpOnly: true,
secure: true,
secure: !!this.configService.getOrThrow('cookies.secure'),
domain: this.configService.getOrThrow('cookies.domain'),
path: '/',
expires,
sameSite: 'none',
sameSite: this.configService.getOrThrow('cookies.secure')
? 'none'
: 'lax',
},
);

Expand Down Expand Up @@ -161,11 +163,13 @@ export class SignInCoreSessionsService {
login_token,
{
httpOnly: true,
secure: true,
secure: !!this.configService.getOrThrow('cookies.secure'),
domain: this.configService.getOrThrow('cookies.domain'),
path: '/',
expires: remember ? expires : undefined,
sameSite: 'none',
sameSite: this.configService.getOrThrow('cookies.secure')
? 'none'
: 'lax',
},
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ export class SignOutCoreSessionsService {

res.clearCookie(this.configService.getOrThrow('cookies.login_token.name'), {
httpOnly: true,
secure: true,
secure: !!this.configService.getOrThrow('cookies.secure'),
domain: this.configService.getOrThrow('cookies.domain'),
path: '/',
sameSite: 'none',
sameSite: this.configService.getOrThrow('cookies.secure')
? 'none'
: 'lax',
});

return 'You are logged out';
Expand Down

0 comments on commit d5b01ac

Please sign in to comment.