mirror of
https://github.com/nikdoof/pocket-id.git
synced 2025-12-13 23:02:17 +00:00
fix: add __HOST prefix to cookies (#175)
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { env } from '$env/dynamic/private';
|
||||
import { ACCESS_TOKEN_COOKIE_NAME } from '$lib/constants';
|
||||
import type { Handle, HandleServerError } from '@sveltejs/kit';
|
||||
import { AxiosError } from 'axios';
|
||||
import jwt from 'jsonwebtoken';
|
||||
@@ -9,7 +10,7 @@ import jwt from 'jsonwebtoken';
|
||||
process.env.INTERNAL_BACKEND_URL = env.INTERNAL_BACKEND_URL ?? 'http://localhost:8080';
|
||||
|
||||
export const handle: Handle = async ({ event, resolve }) => {
|
||||
const accessToken = event.cookies.get('access_token');
|
||||
const accessToken = event.cookies.get(ACCESS_TOKEN_COOKIE_NAME);
|
||||
|
||||
let isSignedIn: boolean = false;
|
||||
let isAdmin: boolean = false;
|
||||
|
||||
2
frontend/src/lib/constants.ts
Normal file
2
frontend/src/lib/constants.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
export const HTTPS_ENABLED = process.env.PUBLIC_APP_URL?.startsWith('https://') ?? false;
|
||||
export const ACCESS_TOKEN_COOKIE_NAME = HTTPS_ENABLED ? '__Host-access_token' : 'access_token';
|
||||
@@ -1,10 +1,11 @@
|
||||
import { ACCESS_TOKEN_COOKIE_NAME } from '$lib/constants';
|
||||
import AppConfigService from '$lib/services/app-config-service';
|
||||
import UserService from '$lib/services/user-service';
|
||||
import type { LayoutServerLoad } from './$types';
|
||||
|
||||
export const load: LayoutServerLoad = async ({ cookies }) => {
|
||||
const userService = new UserService(cookies.get('access_token'));
|
||||
const appConfigService = new AppConfigService(cookies.get('access_token'));
|
||||
const userService = new UserService(cookies.get(ACCESS_TOKEN_COOKIE_NAME));
|
||||
const appConfigService = new AppConfigService(cookies.get(ACCESS_TOKEN_COOKIE_NAME));
|
||||
|
||||
const user = await userService
|
||||
.getCurrent()
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { ACCESS_TOKEN_COOKIE_NAME } from '$lib/constants';
|
||||
import OidcService from '$lib/services/oidc-service';
|
||||
import type { PageServerLoad } from './$types';
|
||||
|
||||
export const load: PageServerLoad = async ({ url, cookies }) => {
|
||||
const clientId = url.searchParams.get('client_id');
|
||||
const oidcService = new OidcService(cookies.get('access_token'));
|
||||
const oidcService = new OidcService(cookies.get(ACCESS_TOKEN_COOKIE_NAME));
|
||||
|
||||
const client = await oidcService.getClient(clientId!);
|
||||
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { ACCESS_TOKEN_COOKIE_NAME } from '$lib/constants';
|
||||
import UserService from '$lib/services/user-service';
|
||||
import WebAuthnService from '$lib/services/webauthn-service';
|
||||
import type { PageServerLoad } from './$types';
|
||||
|
||||
export const load: PageServerLoad = async ({ cookies }) => {
|
||||
const webauthnService = new WebAuthnService(cookies.get('access_token'));
|
||||
const userService = new UserService(cookies.get('access_token'));
|
||||
const webauthnService = new WebAuthnService(cookies.get(ACCESS_TOKEN_COOKIE_NAME));
|
||||
const userService = new UserService(cookies.get(ACCESS_TOKEN_COOKIE_NAME));
|
||||
const account = await userService.getCurrent();
|
||||
const passkeys = await webauthnService.listCredentials();
|
||||
return {
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import { ACCESS_TOKEN_COOKIE_NAME } from '$lib/constants';
|
||||
import AppConfigService from '$lib/services/app-config-service';
|
||||
import type { PageServerLoad } from './$types';
|
||||
|
||||
export const load: PageServerLoad = async ({ cookies }) => {
|
||||
const appConfigService = new AppConfigService(cookies.get('access_token'));
|
||||
const appConfigService = new AppConfigService(cookies.get(ACCESS_TOKEN_COOKIE_NAME));
|
||||
const appConfig = await appConfigService.list(true);
|
||||
return { appConfig };
|
||||
};
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import { ACCESS_TOKEN_COOKIE_NAME } from '$lib/constants';
|
||||
import OIDCService from '$lib/services/oidc-service';
|
||||
import type { PageServerLoad } from './$types';
|
||||
|
||||
export const load: PageServerLoad = async ({ cookies }) => {
|
||||
const oidcService = new OIDCService(cookies.get('access_token'));
|
||||
const oidcService = new OIDCService(cookies.get(ACCESS_TOKEN_COOKIE_NAME));
|
||||
const clients = await oidcService.listClients();
|
||||
return clients;
|
||||
};
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { ACCESS_TOKEN_COOKIE_NAME } from '$lib/constants';
|
||||
import OidcService from '$lib/services/oidc-service';
|
||||
import type { PageServerLoad } from './$types';
|
||||
|
||||
export const load: PageServerLoad = async ({ params, cookies }) => {
|
||||
const oidcService = new OidcService(cookies.get('access_token'));
|
||||
const oidcService = new OidcService(cookies.get(ACCESS_TOKEN_COOKIE_NAME));
|
||||
return await oidcService.getClient(params.id);
|
||||
};
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import { ACCESS_TOKEN_COOKIE_NAME } from '$lib/constants';
|
||||
import UserGroupService from '$lib/services/user-group-service';
|
||||
import type { PageServerLoad } from './$types';
|
||||
|
||||
export const load: PageServerLoad = async ({ cookies }) => {
|
||||
const userGroupService = new UserGroupService(cookies.get('access_token'));
|
||||
const userGroupService = new UserGroupService(cookies.get(ACCESS_TOKEN_COOKIE_NAME));
|
||||
const userGroups = await userGroupService.list();
|
||||
return userGroups;
|
||||
};
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import { ACCESS_TOKEN_COOKIE_NAME } from '$lib/constants';
|
||||
import UserGroupService from '$lib/services/user-group-service';
|
||||
import type { PageServerLoad } from './$types';
|
||||
|
||||
export const load: PageServerLoad = async ({ params, cookies }) => {
|
||||
const userGroupService = new UserGroupService(cookies.get('access_token'));
|
||||
const userGroupService = new UserGroupService(cookies.get(ACCESS_TOKEN_COOKIE_NAME));
|
||||
const userGroup = await userGroupService.get(params.id);
|
||||
|
||||
return { userGroup };
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import { ACCESS_TOKEN_COOKIE_NAME } from '$lib/constants';
|
||||
import UserService from '$lib/services/user-service';
|
||||
import type { PageServerLoad } from './$types';
|
||||
|
||||
export const load: PageServerLoad = async ({ cookies }) => {
|
||||
const userService = new UserService(cookies.get('access_token'));
|
||||
const userService = new UserService(cookies.get(ACCESS_TOKEN_COOKIE_NAME));
|
||||
const users = await userService.list();
|
||||
return users;
|
||||
};
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import { ACCESS_TOKEN_COOKIE_NAME } from '$lib/constants';
|
||||
import UserService from '$lib/services/user-service';
|
||||
import type { PageServerLoad } from './$types';
|
||||
|
||||
export const load: PageServerLoad = async ({ params, cookies }) => {
|
||||
const userService = new UserService(cookies.get('access_token'));
|
||||
const userService = new UserService(cookies.get(ACCESS_TOKEN_COOKIE_NAME));
|
||||
const user = await userService.get(params.id);
|
||||
return user;
|
||||
};
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import { ACCESS_TOKEN_COOKIE_NAME } from '$lib/constants';
|
||||
import AuditLogService from '$lib/services/audit-log-service';
|
||||
import type { PageServerLoad } from './$types';
|
||||
|
||||
export const load: PageServerLoad = async ({ cookies }) => {
|
||||
const auditLogService = new AuditLogService(cookies.get('access_token'));
|
||||
const auditLogService = new AuditLogService(cookies.get(ACCESS_TOKEN_COOKIE_NAME));
|
||||
const auditLogs = await auditLogService.list({
|
||||
sort: {
|
||||
column: 'createdAt',
|
||||
|
||||
Reference in New Issue
Block a user