nuxt-auth-utils 0.0.15 → 0.0.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -90,6 +90,7 @@ The following helpers are auto-imported in your `server/` directory.
90
90
  ```ts
91
91
  // Set a user session, note that this data is encrypted in the cookie but can be decrypted with an API call
92
92
  // Only store the data that allow you to recognize an user, but do not store sensitive data
93
+ // Merges new data with existing data using defu()
93
94
  await setUserSession(event, {
94
95
  user: {
95
96
  // ... user data
@@ -98,6 +99,9 @@ await setUserSession(event, {
98
99
  // Any extra fields
99
100
  })
100
101
 
102
+ // Replace a user session. Same behaviour as setUserSession, except it does not merge data with existing data
103
+ await replaceUserSession(event, data)
104
+
101
105
  // Get the current user session
102
106
  const session = await getUserSession(event)
103
107
 
@@ -112,10 +116,15 @@ You can define the type for your user session by creating a type declaration fil
112
116
 
113
117
  ```ts
114
118
  declare module '#auth-utils' {
119
+ interface User {
120
+ // Add your own fields
121
+ }
122
+
115
123
  interface UserSession {
116
- // define the type here
124
+ // Add your own fields
117
125
  }
118
126
  }
127
+
119
128
  export {}
120
129
  ```
121
130
 
@@ -239,14 +248,14 @@ npm run release
239
248
  ```
240
249
 
241
250
  <!-- Badges -->
242
- [npm-version-src]: https://img.shields.io/npm/v/nuxt-auth-utils/latest.svg?style=flat&colorA=18181B&colorB=28CF8D
251
+ [npm-version-src]: https://img.shields.io/npm/v/nuxt-auth-utils/latest.svg?style=flat&colorA=020420&colorB=00DC82
243
252
  [npm-version-href]: https://npmjs.com/package/nuxt-auth-utils
244
253
 
245
- [npm-downloads-src]: https://img.shields.io/npm/dm/nuxt-auth-utils.svg?style=flat&colorA=18181B&colorB=28CF8D
254
+ [npm-downloads-src]: https://img.shields.io/npm/dm/nuxt-auth-utils.svg?style=flat&colorA=020420&colorB=00DC82
246
255
  [npm-downloads-href]: https://npmjs.com/package/nuxt-auth-utils
247
256
 
248
- [license-src]: https://img.shields.io/npm/l/nuxt-auth-utils.svg?style=flat&colorA=18181B&colorB=28CF8D
257
+ [license-src]: https://img.shields.io/npm/l/nuxt-auth-utils.svg?style=flat&colorA=020420&colorB=00DC82
249
258
  [license-href]: https://npmjs.com/package/nuxt-auth-utils
250
259
 
251
- [nuxt-src]: https://img.shields.io/badge/Nuxt-18181B?logo=nuxt.js
260
+ [nuxt-src]: https://img.shields.io/badge/Nuxt-020420?logo=nuxt.js
252
261
  [nuxt-href]: https://nuxt.com
package/dist/module.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "auth-utils",
3
3
  "configKey": "auth",
4
- "version": "0.0.15"
4
+ "version": "0.0.17"
5
5
  }
package/dist/module.mjs CHANGED
@@ -33,6 +33,7 @@ const module = defineNuxtModule({
33
33
  "sessionHooks",
34
34
  "getUserSession",
35
35
  "setUserSession",
36
+ "replaceUserSession",
36
37
  "clearUserSession",
37
38
  "requireUserSession"
38
39
  ]
@@ -1,2 +1,2 @@
1
- declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<UserSession>>;
1
+ declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<any>>;
2
2
  export default _default;
@@ -27,10 +27,5 @@ export interface OAuthGoogleConfig {
27
27
  * @default 'https://oauth2.googleapis.com/token'
28
28
  */
29
29
  tokenURL?: string;
30
- /**
31
- * Redirect URL post authenticating via google
32
- * @default '/auth/google'
33
- */
34
- redirectUrl: '/auth/google';
35
30
  }
36
31
  export declare function googleEventHandler({ config, onSuccess, onError, }: OAuthConfig<OAuthGoogleConfig>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<any>>;
@@ -0,0 +1,3 @@
1
+ {
2
+ "extends": "../../../.nuxt/tsconfig.server.json"
3
+ }
@@ -20,5 +20,11 @@ export declare function getUserSession(event: H3Event): Promise<UserSession>;
20
20
  * @param data User session data, please only store public information since it can be decoded with API calls
21
21
  */
22
22
  export declare function setUserSession(event: H3Event, data: UserSession): Promise<UserSession>;
23
+ /**
24
+ * Replace a user session
25
+ * @param event
26
+ * @param data User session data, please only store public information since it can be decoded with API calls
27
+ */
28
+ export declare function replaceUserSession(event: H3Event, data: UserSession): Promise<UserSession>;
23
29
  export declare function clearUserSession(event: H3Event): Promise<boolean>;
24
- export declare function requireUserSession(event: H3Event): Promise<UserSession>;
30
+ export declare function requireUserSession(event: H3Event): Promise<any>;
@@ -11,6 +11,12 @@ export async function setUserSession(event, data) {
11
11
  await session.update(defu(data, session.data));
12
12
  return session.data;
13
13
  }
14
+ export async function replaceUserSession(event, data) {
15
+ const session = await _useSession(event);
16
+ await session.clear();
17
+ await session.update(data);
18
+ return session.data;
19
+ }
14
20
  export async function clearUserSession(event) {
15
21
  const session = await _useSession(event);
16
22
  await sessionHooks.callHookParallel("clear", session.data, event);
@@ -1,2 +1,2 @@
1
- export type { UserSession } from './session';
1
+ export type { UserSession, User } from './session';
2
2
  export type { OAuthConfig } from './oauth-config';
@@ -1,3 +1,5 @@
1
+ export interface User {
2
+ }
1
3
  export interface UserSession {
2
- user?: {};
4
+ user?: User;
3
5
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-auth-utils",
3
- "version": "0.0.15",
3
+ "version": "0.0.17",
4
4
  "description": "Minimalist Auth module for Nuxt with SSR",
5
5
  "repository": "Atinux/nuxt-auth-utils",
6
6
  "license": "MIT",
@@ -30,25 +30,25 @@
30
30
  "test:watch": "vitest watch"
31
31
  },
32
32
  "dependencies": {
33
- "@nuxt/kit": "^3.9.3",
33
+ "@nuxt/kit": "^3.10.2",
34
34
  "defu": "^6.1.4",
35
35
  "hookable": "^5.5.3",
36
36
  "ofetch": "^1.3.3",
37
37
  "ohash": "^1.1.3"
38
38
  },
39
39
  "devDependencies": {
40
- "@iconify-json/simple-icons": "^1.1.90",
40
+ "@iconify-json/simple-icons": "^1.1.91",
41
41
  "@nuxt/devtools": "latest",
42
42
  "@nuxt/eslint-config": "^0.2.0",
43
43
  "@nuxt/module-builder": "^0.5.5",
44
- "@nuxt/schema": "^3.9.3",
44
+ "@nuxt/schema": "^3.10.2",
45
45
  "@nuxt/test-utils": "^3.11.0",
46
- "@nuxt/ui": "^2.12.3",
47
- "@nuxt/ui-pro": "^0.7.3",
48
- "@types/node": "^20.11.10",
46
+ "@nuxt/ui": "^2.13.0",
47
+ "@nuxt/ui-pro": "^0.7.5",
48
+ "@types/node": "^20.11.19",
49
49
  "changelogen": "^0.5.5",
50
50
  "eslint": "^8.56.0",
51
- "nuxt": "^3.9.3",
51
+ "nuxt": "^3.10.2",
52
52
  "typescript": "^5.3.3",
53
53
  "vitest": "^1.2.2",
54
54
  "vue-tsc": "^1.8.27"