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