Skip to content

Commit 6374264

Browse files
committed
Improve "Create a strategy" docs to be more correct with current API
1 parent 8aadb58 commit 6374264

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

README.md

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,10 @@ All strategies extends the `Strategy` abstract class exported by Remix Auth. You
223223
import { Strategy } from "remix-auth/strategy";
224224

225225
export namespace MyStrategy {
226+
export interface ConstructorOptions {
227+
// The values you will pass to the constructor
228+
}
229+
226230
export interface VerifyOptions {
227231
// The values you will pass to the verify function
228232
}
@@ -231,11 +235,15 @@ export namespace MyStrategy {
231235
export class MyStrategy<User> extends Strategy<User, MyStrategy.VerifyOptions> {
232236
name = "my-strategy";
233237

234-
async authenticate(
235-
request: Request,
236-
options: Strategy.AuthenticateOptions
237-
): Promise<User> {
238-
// Your logic here
238+
constructor(
239+
protected options: MyStrategy.ConstructorOptions,
240+
verify: Strategy.VerifyFunction<User, MyStrategy.VerifyOptions>
241+
) {
242+
super(verify);
243+
}
244+
245+
async authenticate(request: Request): Promise<User> {
246+
// Your logic here, you can use `this.options` to get constructor options
239247
}
240248
}
241249
```
@@ -246,12 +254,16 @@ At some point of your `authenticate` method, you will need to call `this.verify(
246254
export class MyStrategy<User> extends Strategy<User, MyStrategy.VerifyOptions> {
247255
name = "my-strategy";
248256

249-
async authenticate(
250-
request: Request,
251-
options: Strategy.AuthenticateOptions
252-
): Promise<User> {
257+
constructor(
258+
protected options: MyStrategy.ConstructorOptions,
259+
verify: Strategy.VerifyFunction<User, MyStrategy.VerifyOptions>
260+
) {
261+
super(verify);
262+
}
263+
264+
async authenticate(request: Request): Promise<User> {
253265
return await this.verify({
254-
/* your options here */
266+
/* your verify options here */
255267
});
256268
}
257269
}
@@ -263,7 +275,7 @@ What you want to pass to the `verify` method is up to you and what your authenti
263275

264276
#### Store intermediate state
265277

266-
If your strategy needs to store intermediate state, you can use override the `contructor` method to expect a `Cookie` object, or even a `SessionStorage` object.
278+
If your strategy needs to store intermediate state, you can override the `contructor` method to expect a `Cookie` object, or even a `SessionStorage` object.
267279

268280
```ts
269281
import { SetCookie } from "@mjackson/headers";

0 commit comments

Comments
 (0)