Skip to content

Commit 7535444

Browse files
authored
🔄 synced local 'content/2.nuxt-auth/' with remote 'docs/content/' (#183)
Co-authored-by: sideborg <null>
1 parent ac15bd4 commit 7535444

File tree

2 files changed

+86
-5
lines changed

2 files changed

+86
-5
lines changed

content/2.nuxt-auth/2.configuration/2.nuxt-config.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ interface ModuleOptions {
6868
* Configuration of the application-side session. You can configure the following attributes:
6969
* - enableRefreshPeriodically: Whether to refresh the session every `X` milliseconds. Set this to `false` to turn it off. The session will only be refreshed if a session already exists. Setting this to `true` will refresh the session every second. Setting this to `false` will turn off session refresh. Setting this to a number `X` will refresh the session every `X` milliseconds.
7070
* - enableRefreshOnWindowFocus: Whether to refresh the session every time the browser window is refocused.
71-
*
71+
*
7272
* @example { enableRefreshPeriodically: 5000 }
7373
* @example { enableRefreshOnWindowFocus: false }
7474
* @default { enableRefreshPeriodically: false, enableRefreshOnWindowFocus: true }
@@ -231,7 +231,7 @@ type ProviderLocal = {
231231
*/
232232
maxAgeInSeconds?: number,
233233
/**
234-
* The cookie sameSite policy. Can be used as a form of csrf forgery protection. If set to `strict`, the cookie will only be passed with requests to the same 'site'. Typically, this includes subdomains. So, a sameSite: strict cookie set by app.mysite.com will be passed to api.mysite.com, but not api.othersite.com.
234+
* The cookie sameSite policy. Can be used as a form of csrf forgery protection. If set to `strict`, the cookie will only be passed with requests to the same 'site'. Typically, this includes subdomains. So, a sameSite: strict cookie set by app.mysite.com will be passed to api.mysite.com, but not api.othersite.com.
235235
*
236236
* See the specification here: https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-rfc6265bis-03#section-4.1.2.7
237237
*
@@ -337,8 +337,8 @@ type ProviderRefresh = {
337337
refresh?: { path?: string, method?: RouterMethod },
338338
},
339339
/**
340-
* When refreshOnlyToken is set, only the token will be refreshed
341-
*
340+
* When refreshOnlyToken is set, only the token will be refreshed
341+
*
342342
* @default true
343343
*/
344344
refreshOnlyToken?: boolean;
@@ -400,7 +400,7 @@ type ProviderRefresh = {
400400
*/
401401
maxAgeInSeconds?: number,
402402
/**
403-
* The cookie sameSite policy. Can be used as a form of csrf forgery protection. If set to `strict`, the cookie will only be passed with requests to the same 'site'. Typically, this includes subdomains. So, a sameSite: strict cookie set by app.mysite.com will be passed to api.mysite.com, but not api.othersite.com.
403+
* The cookie sameSite policy. Can be used as a form of csrf forgery protection. If set to `strict`, the cookie will only be passed with requests to the same 'site'. Typically, this includes subdomains. So, a sameSite: strict cookie set by app.mysite.com will be passed to api.mysite.com, but not api.othersite.com.
404404
*
405405
* See the specification here: https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-rfc6265bis-03#section-4.1.2.7
406406
*
@@ -529,6 +529,14 @@ type SessionConfig = {
529529
* @default true
530530
*/
531531
enableRefreshOnWindowFocus: boolean
532+
/**
533+
* A custom refresh handler to use. This can be used to implement custom session refresh logic.
534+
* If not set, the default refresh handler will be used.
535+
*
536+
* @example ./src/runtime/utils/refreshHandler.ts
537+
* @default undefined
538+
*/
539+
refreshHandler?: RefreshHandler;
532540
}
533541
```
534542
```ts [GlobalMiddlewareOptions]
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# Session Config
2+
3+
Use this section to configure the application-side session. The following type defines the options you can use inside your auths `session`-key:
4+
5+
```ts
6+
/**
7+
* Configuration for the application-side session.
8+
*/
9+
type SessionConfig = {
10+
/**
11+
* Whether to refresh the session every `X` milliseconds. Set this to `false` to turn it off. The session will only be refreshed if a session already exists.
12+
*
13+
* Setting this to `true` will refresh the session every second.
14+
* Setting this to `false` will turn off session refresh.
15+
* Setting this to a number `X` will refresh the session every `X` milliseconds.
16+
*
17+
* @example 1000
18+
* @default false
19+
*
20+
*/
21+
enableRefreshPeriodically: number | boolean
22+
/**
23+
* Whether to refresh the session every time the browser window is refocused.
24+
*
25+
* @example false
26+
* @default true
27+
*/
28+
enableRefreshOnWindowFocus: boolean
29+
/**
30+
* A custom refresh handler to use. This can be used to implement custom session refresh logic.
31+
* If not set, the default refresh handler will be used.
32+
*
33+
* @example ./src/runtime/utils/refreshHandler.ts
34+
* @default undefined
35+
*/
36+
refreshHandler?: RefreshHandler;
37+
}
38+
```
39+
40+
## Application side session
41+
42+
Per default nuxt-auth will use the set values for `enableRefreshPeriodically` & `enableRefreshOnWindowFocus` to refresh your application-side session. If you don't provide a configuration nuxt-auth won't trigger a job that refreshes the session periodically but it will always refresh the session if the window is refocussed.
43+
44+
If you set `enableRefreshPeriodically` simply to true a job will be run every second (1000ms) that will fetch your specified `getSession` endpoint. You can customize the interval if you provide a number instead of a boolean value.
45+
46+
To disable the session refresh when the window is refocussed simply set `enableRefreshOnWindowFocus` to `false`.
47+
48+
## Using a custom RefreshHandler
49+
50+
To customize the session refreshing you can provide a refresh handler. A custom `RefreshHandler` requires an `init`- and a `destroy`-function.
51+
52+
`init` will be called when the nuxt application is mounted. Here you may add event listeners and initialize custom refresh behaviour. The method will receive a `RefreshHandlerConfig`. The type consists of `enableRefreshPeriodically` & `enableRefreshOnWindowFocus`.
53+
54+
`destroy` will be called when your app is unmounted. Here you may run your clean up routine e.g. to remove your event listeners.
55+
56+
```ts
57+
export type RefreshHandler = {
58+
/**
59+
* Initializes the refresh handler with the given configuration.
60+
* init will be called inside app:mouted lifecycle hook.
61+
*
62+
* @param config The configuration to use for the refresh handler.
63+
*/
64+
init: (config: RefreshHandlerConfig) => void;
65+
66+
/**
67+
* Handles cleanup of the refresh handler. This method will be called when the app is destroyed.
68+
*/
69+
destroy: () => void;
70+
};
71+
```
72+
73+
To get an idea the `defaultRefreshHandler` could be useful.

0 commit comments

Comments
 (0)