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: docs/content/1.getting-started/3.quick-start.md
+50-1Lines changed: 50 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -91,20 +91,69 @@ and return a token that can be used to authenticate future requests in the respo
91
91
}
92
92
```
93
93
94
+
### Provider: `refresh`
95
+
96
+
The refresh provider does not require any additional steps, as it relies on an already existing backend. By default, the `refresh` provider will try to reach this backend using the following default-configuration:
97
+
```ts
98
+
{
99
+
baseURL: '/api/auth',
100
+
endpoints: {
101
+
signIn: { path: '/login', method: 'post' },
102
+
signOut: { path: '/logout', method: 'post' },
103
+
signUp: { path: '/register', method: 'post' },
104
+
getSession: { path: '/session', method: 'get' }
105
+
refresh: { path: '/refresh', method: 'post' },
106
+
}
107
+
}
108
+
```
109
+
110
+
So when you call the `signIn` method, the endpoint `/api/auth/login` will be hit with the `username` and `password` you pass as a body-payload. You likely have to modify these parameters to fit to your backend - you can adjust these parameters in your `nuxt.config.ts` using the options [specified here](/nuxt-auth/v0.6/configuration/nuxt-config).
111
+
112
+
Note: The backend can also be in the same Nuxt 3 application, e.g., have a look at this example in the `nuxt-auth` repository:
and return a token that can be used to authenticate future requests in the response body, e.g., like:
130
+
```ts
131
+
{
132
+
tokens: {
133
+
accessToken: 'eyBlaBlub'
134
+
refreshToken: 'eyBlaubwww'
135
+
}
136
+
}
137
+
```
138
+
139
+
So when you call the `refresh` method, the endpoint `/api/auth/refresh` will be hit with the `refreshToken` you pass as a body-payload. You likely have to modify these parameters to fit to your backend - you can adjust these parameters in your `nuxt.config.ts` using the options [specified here](/nuxt-auth/v0.6/configuration/nuxt-config).
140
+
94
141
## Finishing up
95
142
96
143
That's it! You can now use all user-related functionality, for example:
* What method and path to call to perform the sign-up.
266
+
*
267
+
* @default{ path: '/register', method: 'post' }
268
+
*/
269
+
signUp?: { path?:string, method?:RouterMethod },
270
+
/**
271
+
* What method and path to call to fetch user / session data from. `nuxt-auth` will send the token received upon sign-in as a header along this request to authenticate.
272
+
*
273
+
* Refer to the `token` configuration to configure how `nuxt-auth` uses the token in this request. By default it will be send as a bearer-authentication header like so: `Authentication: Bearer eyNDSNJDASNMDSA....`
* What method and path to call to perform the refresh.
281
+
*
282
+
* @default{ path: '/refresh', method: 'post' }
283
+
*/
284
+
refresh?: { path?:string, method?:RouterMethod },
285
+
},
286
+
/**
287
+
* When refreshOnlyToken is set, only the token will be refreshed
288
+
*
289
+
*
290
+
*/
291
+
refreshOnlyToken?:true;
292
+
/**
293
+
* Pages that `nuxt-auth` needs to know the location off for redirects.
294
+
*/
295
+
pages?: {
296
+
/**
297
+
* Path of the login-page that the user should be redirected to, when they try to access a protected page without being logged in. This page will also not be blocked by the global middleware.
298
+
*
299
+
* @default'/login'
300
+
*/
301
+
login?:string
302
+
},
303
+
/**
304
+
* Settings for the authentication-token that `nuxt-auth` receives from the `signIn` endpoint and that can be used to authenticate subsequent requests.
305
+
*/
306
+
token?: {
307
+
/**
308
+
* How to extract the authentication-token from the sign-in response.
309
+
*
310
+
* E.g., setting this to `/token/bearer` and returning an object like `{ token: { bearer: 'THE_AUTH_TOKEN' }, timestamp: '2023' }` from the `signIn` endpoint will
311
+
* result in `nuxt-auth` extracting and storing `THE_AUTH_TOKEN`.
312
+
*
313
+
* This follows the JSON Pointer standard, see it's RFC6901 here: https://www.rfc-editor.org/rfc/rfc6901
314
+
*
315
+
* @default/token Access the `token` property of the sign-in response object
316
+
* @example/ Access the root of the sign-in response object, useful when your endpoint returns a plain, non-object string as the token
317
+
*/
318
+
signInResponseTokenPointer?:string
319
+
/**
320
+
* Header type to be used in requests. This in combination with `headerName` is used to construct the final authentication-header `nuxt-auth` uses, e.g, for requests via `getSession`.
321
+
*
322
+
* @defaultBearer
323
+
* @exampleBeer
324
+
*/
325
+
type?:string,
326
+
/**
327
+
* Header name to be used in requests that need to be authenticated, e.g., to be used in the `getSession` request.
328
+
*
329
+
* @defaultAuthorization
330
+
* @exampleAuth
331
+
*/
332
+
headerName?:string,
333
+
/**
334
+
* Maximum age to store the authentication token for. After the expiry time the token is automatically deleted on the application side, i.e., in the users' browser.
335
+
*
336
+
* Note: Your backend may reject / expire the token earlier / differently.
337
+
*
338
+
* @default1800
339
+
* @example60 * 60 * 24
340
+
*/
341
+
maxAgeInSeconds?:number,
342
+
/**
343
+
* 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.
344
+
*
345
+
* See the specification here: https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-rfc6265bis-03#section-4.1.2.7
* Settings for the authentication-refreshToken that `nuxt-auth` receives from the `signIn` endpoint and that can be used to authenticate subsequent requests.
354
+
*/
355
+
refreshToken?: {
356
+
/**
357
+
* How to extract the authentication-refreshToken from the sign-in response.
358
+
*
359
+
* E.g., setting this to `/token/refreshToken` and returning an object like `{ token: { refreshToken: 'THE_REFRESH__TOKEN' }, timestamp: '2023' }` from the `signIn` endpoint will
360
+
* result in `nuxt-auth` extracting and storing `THE_REFRESH__TOKEN`.
361
+
*
362
+
* This follows the JSON Pointer standard, see it's RFC6901 here: https://www.rfc-editor.org/rfc/rfc6901
363
+
*
364
+
* @default/refreshToken Access the `refreshToken` property of the sign-in response object
365
+
* @example/ Access the root of the sign-in response object, useful when your endpoint returns a plain, non-object string as the refreshToken
366
+
*/
367
+
signInResponseRefreshTokenPointer?:string
368
+
/**
369
+
* Maximum age to store the authentication token for. After the expiry time the token is automatically deleted on the application side, i.e., in the users' browser.
370
+
*
371
+
* Note: Your backend may reject / expire the refreshToken earlier / differently.
372
+
*
373
+
* @default1800
374
+
* @example60 * 60 * 24
375
+
*/
376
+
maxAgeInSeconds?:number,
377
+
},
378
+
/**
379
+
* Define an interface for the session data object that `nuxt-auth` expects to receive from the `getSession` endpoint.
0 commit comments