nuxt-auth-utils 0.0.10 → 0.0.11
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
|
@@ -188,6 +188,25 @@ export default oauth.githubEventHandler({
|
|
|
188
188
|
|
|
189
189
|
Make sure to set the callback URL in your OAuth app settings as `<your-domain>/auth/github`.
|
|
190
190
|
|
|
191
|
+
### Extend Session
|
|
192
|
+
|
|
193
|
+
We leverage hooks to let you extend the session data with your own data or to log when the user clear its session.
|
|
194
|
+
|
|
195
|
+
```ts
|
|
196
|
+
// server/plugins/session.ts
|
|
197
|
+
export default defineNitroPlugin(() => {
|
|
198
|
+
sessionHooks.hook('verify', async (session, event) => {
|
|
199
|
+
// extend User Session by calling your database
|
|
200
|
+
// or
|
|
201
|
+
// throw createError({ ... }) if session is invalid for example
|
|
202
|
+
})
|
|
203
|
+
|
|
204
|
+
sessionHooks.hook('clear', async (session, event) => {
|
|
205
|
+
// Log that user logged out
|
|
206
|
+
})
|
|
207
|
+
})
|
|
208
|
+
```
|
|
209
|
+
|
|
191
210
|
## Development
|
|
192
211
|
|
|
193
212
|
```bash
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { eventHandler } from "h3";
|
|
2
|
-
import { requireUserSession } from "../utils/session.mjs";
|
|
2
|
+
import { requireUserSession, sessionHooks } from "../utils/session.mjs";
|
|
3
3
|
export default eventHandler(async (event) => {
|
|
4
|
-
|
|
4
|
+
const session = await requireUserSession(event);
|
|
5
|
+
await sessionHooks.callHookParallel("verify", event, session);
|
|
6
|
+
return session;
|
|
5
7
|
});
|
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
import type { H3Event } from 'h3';
|
|
2
2
|
import type { UserSession } from '#auth-utils';
|
|
3
|
+
export interface SessionHooks {
|
|
4
|
+
/**
|
|
5
|
+
* Called when fetching the session from the API
|
|
6
|
+
* - Add extra properties to the session
|
|
7
|
+
* - Throw an error if the session could not be verified (with a database for example)
|
|
8
|
+
*/
|
|
9
|
+
'verify': (session: UserSession, event: H3Event) => void | Promise<void>;
|
|
10
|
+
/**
|
|
11
|
+
* Called before clearing the session
|
|
12
|
+
*/
|
|
13
|
+
'clear': (session: UserSession, event: H3Event) => void | Promise<void>;
|
|
14
|
+
}
|
|
15
|
+
export declare const sessionHooks: import("hookable").Hookable<SessionHooks, import("hookable").HookKeys<SessionHooks>>;
|
|
3
16
|
export declare function getUserSession(event: H3Event): Promise<UserSession>;
|
|
4
17
|
/**
|
|
5
18
|
* Set a user session
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { useSession, createError } from "h3";
|
|
2
2
|
import { defu } from "defu";
|
|
3
|
+
import { createHooks } from "hookable";
|
|
3
4
|
import { useRuntimeConfig } from "#imports";
|
|
5
|
+
export const sessionHooks = createHooks();
|
|
4
6
|
export async function getUserSession(event) {
|
|
5
7
|
return (await _useSession(event)).data;
|
|
6
8
|
}
|
|
@@ -11,6 +13,7 @@ export async function setUserSession(event, data) {
|
|
|
11
13
|
}
|
|
12
14
|
export async function clearUserSession(event) {
|
|
13
15
|
const session = await _useSession(event);
|
|
16
|
+
await sessionHooks.callHookParallel("clear", event, session);
|
|
14
17
|
await session.clear();
|
|
15
18
|
return true;
|
|
16
19
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-auth-utils",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.11",
|
|
4
4
|
"description": "Minimalist Auth module for Nuxt with SSR",
|
|
5
5
|
"repository": "Atinux/nuxt-auth-utils",
|
|
6
6
|
"license": "MIT",
|
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@nuxt/kit": "^3.8.2",
|
|
34
34
|
"defu": "^6.1.3",
|
|
35
|
+
"hookable": "^5.5.3",
|
|
35
36
|
"ofetch": "^1.3.3",
|
|
36
37
|
"ohash": "^1.1.3"
|
|
37
38
|
},
|