Skip to content

Commit bb741d9

Browse files
authored
refactor(core): export isAuthAction (#9896)
* refactor(core): export isAuthAction * revert
1 parent 0a81238 commit bb741d9

File tree

3 files changed

+20
-17
lines changed

3 files changed

+20
-17
lines changed

packages/core/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,9 @@ import type {
5555
} from "./types.js"
5656
import type { Provider } from "./providers/index.js"
5757
import { JWTOptions } from "./jwt.js"
58+
import { isAuthAction } from "./lib/utils/actions.js"
5859

59-
export { skipCSRFCheck, raw, setEnvDefaults, createActionURL }
60+
export { skipCSRFCheck, raw, setEnvDefaults, createActionURL, isAuthAction }
6061

6162
export async function Auth(
6263
request: Request,
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import type { AuthAction } from "../../types.js"
2+
3+
const actions: AuthAction[] = [
4+
"providers",
5+
"session",
6+
"csrf",
7+
"signin",
8+
"signout",
9+
"callback",
10+
"verify-request",
11+
"error",
12+
]
13+
14+
export function isAuthAction(action: string): action is AuthAction {
15+
return actions.includes(action as AuthAction)
16+
}

packages/core/src/lib/utils/web.ts

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type {
77
RequestInternal,
88
ResponseInternal,
99
} from "../../types.js"
10+
import { isAuthAction } from "./actions.js"
1011

1112
async function getBody(req: Request): Promise<Record<string, any> | undefined> {
1213
if (!("body" in req) || !req.body || req.method !== "POST") return
@@ -20,17 +21,6 @@ async function getBody(req: Request): Promise<Record<string, any> | undefined> {
2021
}
2122
}
2223

23-
const actions: AuthAction[] = [
24-
"providers",
25-
"session",
26-
"csrf",
27-
"signin",
28-
"signout",
29-
"callback",
30-
"verify-request",
31-
"error",
32-
]
33-
3424
export async function toInternalRequest(
3525
req: Request,
3626
config: AuthConfig
@@ -119,10 +109,6 @@ export function randomString(size: number) {
119109
return Array.from(bytes).reduce(r, "")
120110
}
121111

122-
function isAction(action: string): action is AuthAction {
123-
return actions.includes(action as AuthAction)
124-
}
125-
126112
/** @internal Parse the action and provider id from a URL pathname. */
127113
export function parseActionAndProviderId(
128114
pathname: string,
@@ -145,7 +131,7 @@ export function parseActionAndProviderId(
145131

146132
const [action, providerId] = b
147133

148-
if (!isAction(action))
134+
if (!isAuthAction(action))
149135
throw new UnknownAction(`Cannot parse action at ${pathname}`)
150136

151137
if (providerId && !["signin", "callback"].includes(action))

0 commit comments

Comments
 (0)