remix-auth
Advanced tools
Comparing version 4.0.0 to 4.1.0
@@ -35,2 +35,9 @@ import type { Strategy } from "./strategy.js"; | ||
/** | ||
* Call this method with the name of a strategy you want to get. | ||
* It returns the Strategy instance or null if the strategy is not found. | ||
* @param name | ||
* @returns | ||
*/ | ||
get(name: string): Strategy<User, never> | null; | ||
/** | ||
* Call this to authenticate a request using some strategy. You pass the name | ||
@@ -40,10 +47,6 @@ * of the strategy you want to use and the request to authenticate. | ||
* async function action({ request }: ActionFunctionArgs) { | ||
* let user = await auth.authenticate("some", request); | ||
* let user = await auth.authenticate("strategy-name", request); | ||
* }; | ||
* @example | ||
* async function action({ request, context }: ActionFunctionArgs) { | ||
* let user = await auth.authenticate("some", request, { context }); | ||
* }; | ||
*/ | ||
authenticate(strategy: string, request: Request): Promise<User>; | ||
} |
@@ -40,2 +40,11 @@ /** | ||
/** | ||
* Call this method with the name of a strategy you want to get. | ||
* It returns the Strategy instance or null if the strategy is not found. | ||
* @param name | ||
* @returns | ||
*/ | ||
get(name) { | ||
return this.strategies.get(name) ?? null; | ||
} | ||
/** | ||
* Call this to authenticate a request using some strategy. You pass the name | ||
@@ -45,11 +54,7 @@ * of the strategy you want to use and the request to authenticate. | ||
* async function action({ request }: ActionFunctionArgs) { | ||
* let user = await auth.authenticate("some", request); | ||
* let user = await auth.authenticate("strategy-name", request); | ||
* }; | ||
* @example | ||
* async function action({ request, context }: ActionFunctionArgs) { | ||
* let user = await auth.authenticate("some", request, { context }); | ||
* }; | ||
*/ | ||
authenticate(strategy, request) { | ||
let instance = this.strategies.get(strategy); | ||
let instance = this.get(strategy); | ||
if (!instance) | ||
@@ -56,0 +61,0 @@ throw new ReferenceError(`Strategy ${strategy} not found.`); |
{ | ||
"name": "remix-auth", | ||
"version": "4.0.0", | ||
"version": "4.1.0", | ||
"author": { | ||
@@ -14,9 +14,10 @@ "name": "Sergio Xalambrí", | ||
"devDependencies": { | ||
"@arethetypeswrong/cli": "^0.17.0", | ||
"@arethetypeswrong/cli": "^0.17.1", | ||
"@biomejs/biome": "^1.8.3", | ||
"@mjackson/headers": "^0.8.0", | ||
"@total-typescript/tsconfig": "^1.0.4", | ||
"@types/bun": "^1.1.6", | ||
"typedoc": "^0.26.5", | ||
"typedoc-plugin-mdn-links": "^3.2.6", | ||
"@types/bun": "^1.1.14", | ||
"msw": "^2.7.0", | ||
"typedoc": "^0.27.5", | ||
"typedoc-plugin-mdn-links": "^4.0.5", | ||
"typescript": "^5.5.4" | ||
@@ -23,0 +24,0 @@ }, |
@@ -53,2 +53,9 @@ import { beforeEach, describe, expect, mock, test } from "bun:test"; | ||
}); | ||
test("#get", () => { | ||
let auth = new Authenticator(); | ||
let strategy = new MockStrategy(async () => ({ id: 1 })); | ||
expect(auth.use(strategy)).toBe(auth); | ||
expect(auth.get("mock")).toBe(strategy); | ||
}); | ||
}); |
@@ -45,2 +45,12 @@ import type { Strategy } from "./strategy.js"; | ||
/** | ||
* Call this method with the name of a strategy you want to get. | ||
* It returns the Strategy instance or null if the strategy is not found. | ||
* @param name | ||
* @returns | ||
*/ | ||
get(name: string) { | ||
return this.strategies.get(name) ?? null; | ||
} | ||
/** | ||
* Call this to authenticate a request using some strategy. You pass the name | ||
@@ -50,11 +60,7 @@ * of the strategy you want to use and the request to authenticate. | ||
* async function action({ request }: ActionFunctionArgs) { | ||
* let user = await auth.authenticate("some", request); | ||
* let user = await auth.authenticate("strategy-name", request); | ||
* }; | ||
* @example | ||
* async function action({ request, context }: ActionFunctionArgs) { | ||
* let user = await auth.authenticate("some", request, { context }); | ||
* }; | ||
*/ | ||
authenticate(strategy: string, request: Request): Promise<User> { | ||
let instance = this.strategies.get(strategy); | ||
let instance = this.get(strategy); | ||
if (!instance) throw new ReferenceError(`Strategy ${strategy} not found.`); | ||
@@ -61,0 +67,0 @@ return instance.authenticate(new Request(request.url, request)); |
import { describe, expect, test } from "bun:test"; | ||
import { Cookie, SetCookie } from "@mjackson/headers"; | ||
import { Cookie } from "@mjackson/headers"; | ||
import { Strategy } from "./strategy"; | ||
@@ -4,0 +4,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
28501
384
0
9