Skip to content

Commit 7ff4d9d

Browse files
committed
feat: allow raw response for lib authors
1 parent 26815f7 commit 7ff4d9d

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

packages/core/src/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
import { assertConfig } from "./lib/assert.js"
4040
import { ErrorPageLoop } from "./errors.js"
41-
import { AuthInternal, skipCSRFCheck } from "./lib/index.js"
41+
import { AuthInternal, raw, skipCSRFCheck } from "./lib/index.js"
4242
import renderPage from "./lib/pages/index.js"
4343
import { logger, setLogger, type LoggerInstance } from "./lib/utils/logger.js"
4444
import { toInternalRequest, toResponse } from "./lib/web.js"
@@ -54,7 +54,7 @@ import type {
5454
import type { Provider } from "./providers/index.js"
5555
import { JWTOptions } from "./jwt.js"
5656

57-
export { skipCSRFCheck }
57+
export { skipCSRFCheck, raw }
5858

5959
/**
6060
* Core functionality provided by Auth.js.
@@ -137,6 +137,9 @@ export async function Auth(
137137

138138
const internalResponse = await AuthInternal(internalRequest, config)
139139

140+
// @ts-expect-error TODO: Fix return type
141+
if (config.raw === raw) return internalResponse
142+
140143
const response = await toResponse(internalResponse)
141144

142145
// If the request expects a return URL, send it as JSON
@@ -337,6 +340,7 @@ export interface AuthConfig {
337340
/** @todo */
338341
trustHost?: boolean
339342
skipCSRFCheck?: typeof skipCSRFCheck
343+
raw?: typeof raw
340344
/**
341345
* When set, during an OAuth sign-in flow,
342346
* the `redirect_uri` of the authorization request

packages/core/src/lib/index.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,3 +208,14 @@ export async function AuthInternal<
208208
* passing this value to {@link AuthConfig.skipCSRFCheck}.
209209
*/
210210
export const skipCSRFCheck = Symbol("skip-csrf-check")
211+
212+
/**
213+
* :::danger
214+
* This option is intended for framework authors.
215+
* :::
216+
*
217+
* Auth.js returns a web standard {@link Response} by default, but
218+
* if you are implementing a framework you might want to get access to the raw internal response
219+
* by passing this value to {@link AuthConfig.raw}.
220+
*/
221+
export const raw = Symbol("return-type-raw")

0 commit comments

Comments
 (0)