(
location: string,
options?: {
/** Drop the (invalid) session + auth-hint cookies along the way. */
readonly clearSession?: boolean;
/** Persist a WorkOS-rotated sealed session (refresh tokens are single-use). */
readonly refreshedSession?: string | undefined;
},
)
| 198 | `${SESSION_COOKIE}=${sealed}; ${SESSION_COOKIE_ATTRIBUTES}; Max-Age=${SESSION_MAX_AGE}`; |
| 199 | |
| 200 | const redirect = ( |
| 201 | location: string, |
| 202 | options?: { |
| 203 | /** Drop the (invalid) session + auth-hint cookies along the way. */ |
| 204 | readonly clearSession?: boolean; |
| 205 | /** Persist a WorkOS-rotated sealed session (refresh tokens are single-use). */ |
| 206 | readonly refreshedSession?: string | undefined; |
| 207 | }, |
| 208 | ): Response => { |
| 209 | const headers = new Headers({ location }); |
| 210 | if (options?.clearSession) { |
| 211 | headers.append("set-cookie", `${SESSION_COOKIE}=; ${SESSION_COOKIE_ATTRIBUTES}; Max-Age=0`); |
| 212 | headers.append("set-cookie", `${AUTH_HINT_COOKIE}=; Path=/; SameSite=Lax; Max-Age=0`); |
| 213 | } |
| 214 | if (options?.refreshedSession) { |
| 215 | headers.append("set-cookie", sessionSetCookie(options.refreshedSession)); |
| 216 | } |
| 217 | return new Response(null, { status: 302, headers }); |
| 218 | }; |
| 219 | |
| 220 | export const authGateMiddleware = createMiddleware({ type: "request" }).server( |
| 221 | async ({ pathname, request, next }) => { |
no test coverage detected