(
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;
},
)
| 188 | `${SESSION_COOKIE}=${sealed}; ${SESSION_COOKIE_ATTRIBUTES}; Max-Age=${SESSION_MAX_AGE}`; |
| 189 | |
| 190 | const redirect = ( |
| 191 | location: string, |
| 192 | options?: { |
| 193 | /** Drop the (invalid) session + auth-hint cookies along the way. */ |
| 194 | readonly clearSession?: boolean; |
| 195 | /** Persist a WorkOS-rotated sealed session (refresh tokens are single-use). */ |
| 196 | readonly refreshedSession?: string | undefined; |
| 197 | }, |
| 198 | ): Response => { |
| 199 | const headers = new Headers({ location }); |
| 200 | if (options?.clearSession) { |
| 201 | headers.append("set-cookie", `${SESSION_COOKIE}=; ${SESSION_COOKIE_ATTRIBUTES}; Max-Age=0`); |
| 202 | headers.append("set-cookie", `${AUTH_HINT_COOKIE}=; Path=/; SameSite=Lax; Max-Age=0`); |
| 203 | } |
| 204 | if (options?.refreshedSession) { |
| 205 | headers.append("set-cookie", sessionSetCookie(options.refreshedSession)); |
| 206 | } |
| 207 | return new Response(null, { status: 302, headers }); |
| 208 | }; |
| 209 | |
| 210 | export const authGateMiddleware = createMiddleware({ type: "request" }).server( |
| 211 | async ({ pathname, request, next }) => { |
no test coverage detected