update cloudflare context
This commit is contained in:
@@ -1,17 +1,18 @@
|
||||
import { requestIdContext, userContext } from '@/context'
|
||||
import { createSessionStorage } from '@/session'
|
||||
|
||||
import { createAuth, type User } from '@/auth'
|
||||
import { decodeJwt } from 'jose'
|
||||
import { redirect, type LoaderFunctionArgs } from 'react-router'
|
||||
import type { OAuth2Strategy } from 'remix-auth-oauth2'
|
||||
|
||||
import { requestIdContext, userContext, cloudflareContext } from '../context'
|
||||
import { createSessionStorage } from '../session'
|
||||
import { createAuth, type User } from '../auth'
|
||||
|
||||
export const authMiddleware = async (
|
||||
{ request, context }: LoaderFunctionArgs,
|
||||
next: () => Promise<Response>
|
||||
): Promise<Response> => {
|
||||
const sessionStorage = createSessionStorage(context.cloudflare.env)
|
||||
const authenticator = createAuth(context.cloudflare.env)
|
||||
const cloudflare = context.get(cloudflareContext)
|
||||
const sessionStorage = createSessionStorage(cloudflare.env)
|
||||
const authenticator = createAuth(cloudflare.env)
|
||||
const strategy = authenticator.get<OAuth2Strategy<User>>('oidc')
|
||||
const session = await sessionStorage.getSession(request.headers.get('cookie'))
|
||||
const requestId = context.get(requestIdContext)
|
||||
@@ -51,6 +52,7 @@ export const authMiddleware = async (
|
||||
session.set('user', user)
|
||||
}
|
||||
} catch (error) {
|
||||
// @ts-ignore
|
||||
console.error(`[${requestId}]`, error?.stack)
|
||||
|
||||
// If refreshing the token fails, remove the user from the current session
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { requestIdContext } from '@/context'
|
||||
import { type LoaderFunctionArgs } from 'react-router'
|
||||
|
||||
import { requestIdContext } from '../context'
|
||||
|
||||
export const loggingMiddleware = async (
|
||||
{ request, context }: LoaderFunctionArgs,
|
||||
next
|
||||
) => {
|
||||
next: () => Promise<Response>
|
||||
): Promise<Response> => {
|
||||
const requestId = crypto.randomUUID()
|
||||
context.set(requestIdContext, requestId)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user