mirror of
https://github.com/BradNut/boredgame
synced 2025-09-08 17:40:22 +00:00
Using hono get cookie.
This commit is contained in:
parent
eddb896378
commit
9723cabe80
1 changed files with 3 additions and 3 deletions
|
|
@ -9,8 +9,8 @@ import {
|
||||||
} from '$lib/server/api/common/utils/cookies';
|
} from '$lib/server/api/common/utils/cookies';
|
||||||
import { SessionsService } from '$lib/server/api/services/sessions.service';
|
import { SessionsService } from '$lib/server/api/services/sessions.service';
|
||||||
import type { MiddlewareHandler } from 'hono';
|
import type { MiddlewareHandler } from 'hono';
|
||||||
|
import { getCookie } from 'hono/cookie';
|
||||||
import { createMiddleware } from 'hono/factory';
|
import { createMiddleware } from 'hono/factory';
|
||||||
import { parseCookies } from 'oslo/cookie';
|
|
||||||
import { verifyRequestOrigin } from 'oslo/request';
|
import { verifyRequestOrigin } from 'oslo/request';
|
||||||
import { container } from 'tsyringe';
|
import { container } from 'tsyringe';
|
||||||
import type { AppBindings } from '../common/types/hono';
|
import type { AppBindings } from '../common/types/hono';
|
||||||
|
|
@ -18,6 +18,7 @@ import type { AppBindings } from '../common/types/hono';
|
||||||
// resolve dependencies from the container
|
// resolve dependencies from the container
|
||||||
const sessionService = container.resolve(SessionsService);
|
const sessionService = container.resolve(SessionsService);
|
||||||
|
|
||||||
|
// CSRF protection middleware
|
||||||
export const verifyOrigin: MiddlewareHandler<AppBindings> = createMiddleware(async (c, next) => {
|
export const verifyOrigin: MiddlewareHandler<AppBindings> = createMiddleware(async (c, next) => {
|
||||||
if (c.req.method === 'GET') {
|
if (c.req.method === 'GET') {
|
||||||
return next();
|
return next();
|
||||||
|
|
@ -31,8 +32,7 @@ export const verifyOrigin: MiddlewareHandler<AppBindings> = createMiddleware(asy
|
||||||
});
|
});
|
||||||
|
|
||||||
export const validateAuthSession: MiddlewareHandler<AppBindings> = createMiddleware(async (c, next) => {
|
export const validateAuthSession: MiddlewareHandler<AppBindings> = createMiddleware(async (c, next) => {
|
||||||
const cookies = parseCookies(c.req.header('Cookie') ?? '');
|
const sessionId = getCookie(c, cookieName) ?? null;
|
||||||
const sessionId = cookies.get(cookieName) ?? null;
|
|
||||||
if (!sessionId) {
|
if (!sessionId) {
|
||||||
c.set('user', null);
|
c.set('user', null);
|
||||||
c.set('session', null);
|
c.set('session', null);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue