(
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;
},
)
| 165 | `${SESSION_COOKIE}=${sealed}; ${SESSION_COOKIE_ATTRIBUTES}; Max-Age=${SESSION_MAX_AGE}`; |
| 166 | |
| 167 | const redirect = ( |
| 168 | location: string, |
| 169 | options?: { |
| 170 | /** Drop the (invalid) session + auth-hint cookies along the way. */ |
| 171 | readonly clearSession?: boolean; |
| 172 | /** Persist a WorkOS-rotated sealed session (refresh tokens are single-use). */ |
| 173 | readonly refreshedSession?: string | undefined; |
| 174 | }, |
| 175 | ): Response => { |
| 176 | const headers = new Headers({ location }); |
| 177 | if (options?.clearSession) { |
| 178 | headers.append("set-cookie", `${SESSION_COOKIE}=; ${SESSION_COOKIE_ATTRIBUTES}; Max-Age=0`); |
| 179 | headers.append("set-cookie", `${AUTH_HINT_COOKIE}=; Path=/; SameSite=Lax; Max-Age=0`); |
| 180 | } |
| 181 | if (options?.refreshedSession) { |
| 182 | headers.append("set-cookie", sessionSetCookie(options.refreshedSession)); |
| 183 | } |
| 184 | return new Response(null, { status: 302, headers }); |
| 185 | }; |
| 186 | |
| 187 | export const authGateMiddleware = createMiddleware({ type: "request" }).server( |
| 188 | async ({ pathname, request, next }) => { |
no test coverage detected