You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/2.nuxt-auth/2.configuration/2.nuxt-config.md
+13-5Lines changed: 13 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -68,7 +68,7 @@ interface ModuleOptions {
68
68
* Configuration of the application-side session. You can configure the following attributes:
69
69
* - 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.
70
70
* - enableRefreshOnWindowFocus: Whether to refresh the session every time the browser window is refocused.
* 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.
235
235
*
236
236
* See the specification here: https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-rfc6265bis-03#section-4.1.2.7
237
237
*
@@ -337,8 +337,8 @@ type ProviderRefresh = {
337
337
refresh?: { path?:string, method?:RouterMethod },
338
338
},
339
339
/**
340
-
* When refreshOnlyToken is set, only the token will be refreshed
341
-
*
340
+
* When refreshOnlyToken is set, only the token will be refreshed
341
+
*
342
342
* @defaulttrue
343
343
*/
344
344
refreshOnlyToken?:boolean;
@@ -400,7 +400,7 @@ type ProviderRefresh = {
400
400
*/
401
401
maxAgeInSeconds?:number,
402
402
/**
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.
404
404
*
405
405
* See the specification here: https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-rfc6265bis-03#section-4.1.2.7
406
406
*
@@ -529,6 +529,14 @@ type SessionConfig = {
529
529
* @defaulttrue
530
530
*/
531
531
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.
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
+
typeSessionConfig= {
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
+
* @example1000
18
+
* @defaultfalse
19
+
*
20
+
*/
21
+
enableRefreshPeriodically:number|boolean
22
+
/**
23
+
* Whether to refresh the session every time the browser window is refocused.
24
+
*
25
+
* @examplefalse
26
+
* @defaulttrue
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
+
* @defaultundefined
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
+
exporttypeRefreshHandler= {
58
+
/**
59
+
* Initializes the refresh handler with the given configuration.
60
+
* init will be called inside app:mouted lifecycle hook.
61
+
*
62
+
* @paramconfig 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