Skip to content

Commit 0060358

Browse files
authored
Merge branch 'main' into update-pull-request
2 parents e1a122e + 7f366f0 commit 0060358

File tree

6 files changed

+59
-6
lines changed

6 files changed

+59
-6
lines changed

docs/guide/local/quick-start.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ export default defineNuxtConfig({
141141
maxAgeInSeconds: 1800,
142142
sameSiteAttribute: 'lax',
143143
cookieDomain: 'sidebase.io'
144+
secureCookieAttribute: false,
145+
httpOnlyCookieAttribute: false,
144146
}
145147
}
146148
}
@@ -204,6 +206,20 @@ The cookie domain. See the specification here: https://datatracker.ietf.org/doc/
204206
- **Type:** `string`
205207
- **Default:** `''`
206208
209+
### `secureCookieAttribute`
210+
211+
If set, the cookie will be only sent through `HTTPS` protocol. See the specification here : https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-rfc6265bis-03#section-4.1.2.5
212+
213+
- **Type:** `boolean`
214+
- **Default:** `'false'`
215+
216+
### `httpOnlyCookieAttribute`
217+
218+
If set, the cookie will not be accessible from JavaScript. See the specification here : https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-rfc6265bis-03#section-4.1.2.6
219+
220+
- **Type:** `boolean`
221+
- **Default:** `'false'`
222+
207223
## Refresh token
208224
209225
:::tip
@@ -226,13 +242,17 @@ export default defineNuxtConfig({
226242
maxAgeInSeconds: 1800,
227243
sameSiteAttribute: 'lax',
228244
cookieDomain: 'sidebase.io'
245+
secureCookieAttribute: false,
246+
httpOnlyCookieAttribute: false,
229247
},
230248
refreshToken: {
231249
signInResponseRefreshTokenPointer: '/refresh-token',
232250
refreshRequestTokenPointer: 'Bearer',
233251
cookieName: 'auth.token',
234252
maxAgeInSeconds: 1800,
235253
cookieDomain: 'sidebase.io'
254+
secureCookieAttribute: false,
255+
httpOnlyCookieAttribute: false,
236256
}
237257
}
238258
}
@@ -280,6 +300,20 @@ Note: Your backend may reject / expire the refreshToken earlier / differently.
280300
281301
The cookie domain. See the specification here: https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-rfc6265bis-03#section-4.1.2.3
282302
303+
### `secureCookieAttribute`
304+
305+
If set, the cookie will be only sent through `HTTPS` protocol. See the specification here : https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-rfc6265bis-03#section-4.1.2.5
306+
307+
- **Type:** `boolean`
308+
- **Default:** `'false'`
309+
310+
### `httpOnlyCookieAttribute`
311+
312+
If set, the cookie will not be accessible from JavaScript. See the specification here : https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-rfc6265bis-03#section-4.1.2.6
313+
314+
- **Type:** `boolean`
315+
- **Default:** `'false'`
316+
283317
## `refreshOnlyToken`
284318
285319
:::tip

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@sidebase/nuxt-auth",
3-
"version": "0.8.1",
3+
"version": "0.8.2",
44
"license": "MIT",
55
"type": "module",
66
"engines": {

src/module.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ const defaultsByBackend: {
6464
maxAgeInSeconds: 30 * 60, // 30 minutes
6565
sameSiteAttribute: 'lax',
6666
secureCookieAttribute: false,
67-
cookieDomain: ''
67+
cookieDomain: '',
68+
httpOnlyCookieAttribute: false
6869
},
6970
session: {
7071
dataType: { id: 'string | number' },
@@ -93,15 +94,17 @@ const defaultsByBackend: {
9394
maxAgeInSeconds: 5 * 60, // 5 minutes
9495
sameSiteAttribute: 'none',
9596
secureCookieAttribute: false,
96-
cookieDomain: ''
97+
cookieDomain: '',
98+
httpOnlyCookieAttribute: false
9799
},
98100
refreshToken: {
99101
signInResponseRefreshTokenPointer: '/refreshToken',
100102
refreshRequestTokenPointer: '/refreshToken',
101103
cookieName: 'auth.refresh-token',
102104
maxAgeInSeconds: 60 * 60 * 24 * 7, // 7 days
103105
secureCookieAttribute: false,
104-
cookieDomain: ''
106+
cookieDomain: '',
107+
httpOnlyCookieAttribute: false
105108
},
106109
session: {
107110
dataType: { id: 'string | number' },

src/runtime/composables/local/useAuthState.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ export const useAuthState = (): UseAuthStateReturn => {
3030
domain: config.token.cookieDomain,
3131
maxAge: config.token.maxAgeInSeconds,
3232
sameSite: config.token.sameSiteAttribute,
33-
secure: config.token.secureCookieAttribute
33+
secure: config.token.secureCookieAttribute,
34+
httpOnly: config.token.httpOnlyCookieAttribute
3435
})
3536

3637
const rawToken = useState('auth:raw-token', () => _rawTokenCookie.value)

src/runtime/composables/refresh/useAuthState.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ export const useAuthState = (): UseAuthStateReturn => {
2020
domain: config.refreshToken.cookieDomain,
2121
maxAge: config.refreshToken.maxAgeInSeconds,
2222
sameSite: 'lax',
23-
secure: config.refreshToken.secureCookieAttribute
23+
secure: config.refreshToken.secureCookieAttribute,
24+
httpOnly: config.refreshToken.httpOnlyCookieAttribute
2425
}
2526
)
2627

src/runtime/types.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,13 @@ export type ProviderLocal = {
182182
* @example 'sidebase.io'
183183
*/
184184
cookieDomain?: string;
185+
/**
186+
* Whether to set the httpOnly flag on the cookie.
187+
*
188+
* @default false
189+
* @example true
190+
*/
191+
httpOnlyCookieAttribute?: boolean;
185192
};
186193
/**
187194
* Settings for the session-data that `nuxt-auth` receives from the `getSession` endpoint.
@@ -292,6 +299,13 @@ export type ProviderLocalRefresh = Omit<ProviderLocal, 'type'> & {
292299
* @example 'sidebase.io'
293300
*/
294301
cookieDomain?: string;
302+
/**
303+
* Whether to set the httpOnly flag on the cookie.
304+
*
305+
* @default false
306+
* @example true
307+
*/
308+
httpOnlyCookieAttribute?: boolean;
295309
};
296310
};
297311

0 commit comments

Comments
 (0)