nuxt-auth-utils 0.0.2 → 0.0.4
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 +10 -0
- package/dist/module.json +1 -1
- package/dist/module.mjs +24 -5
- package/dist/runtime/server/api/session.get.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/github.mjs +1 -0
- package/dist/runtime/server/lib/oauth/spotify.mjs +1 -0
- package/dist/runtime/server/utils/session.d.ts +1 -4
- package/dist/runtime/types/auth-utils-session.d.ts +3 -0
- package/dist/runtime/types/auth-utils-session.mjs +0 -0
- package/package.json +10 -6
package/README.md
CHANGED
|
@@ -107,6 +107,16 @@ await clearUserSession(event)
|
|
|
107
107
|
const session = await requireUserSession(event)
|
|
108
108
|
```
|
|
109
109
|
|
|
110
|
+
You can define the type for your user session by creating a type declaration file (for example, `auth.d.ts`) in your project:
|
|
111
|
+
|
|
112
|
+
```ts
|
|
113
|
+
declare module '#auth-utils' {
|
|
114
|
+
interface UserSession {
|
|
115
|
+
// define the type here
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
```
|
|
119
|
+
|
|
110
120
|
### OAuth Event Handlers
|
|
111
121
|
|
|
112
122
|
All helpers are exposed from the `oauth` global variable and can be used in your server routes or API routes.
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -12,16 +12,35 @@ const module = defineNuxtModule({
|
|
|
12
12
|
setup(options, nuxt) {
|
|
13
13
|
const resolver = createResolver(import.meta.url);
|
|
14
14
|
if (!process.env.NUXT_SESSION_PASSWORD) {
|
|
15
|
-
console.warn("No session password set, using a random password, please set NUXT_SESSION_PASSWORD in your .env file with at least 32 chars");
|
|
16
15
|
const randomPassword = sha256(`${Date.now()}${Math.random()}`).slice(0, 32);
|
|
17
|
-
console.log(`NUXT_SESSION_PASSWORD=${randomPassword}`);
|
|
18
16
|
process.env.NUXT_SESSION_PASSWORD = randomPassword;
|
|
17
|
+
if (!nuxt.options._prepare) {
|
|
18
|
+
console.warn("No session password set, using a random password, please set NUXT_SESSION_PASSWORD in your .env file with at least 32 chars");
|
|
19
|
+
console.log(`NUXT_SESSION_PASSWORD=${randomPassword}`);
|
|
20
|
+
}
|
|
19
21
|
}
|
|
22
|
+
nuxt.options.alias["#auth-utils"] = resolver.resolve("./runtime/types/auth-utils-session");
|
|
20
23
|
addImportsDir(resolver.resolve("./runtime/composables"));
|
|
21
24
|
addPlugin(resolver.resolve("./runtime/plugins/session.server"));
|
|
22
|
-
nuxt.options.nitro.imports
|
|
23
|
-
|
|
24
|
-
|
|
25
|
+
if (nuxt.options.nitro.imports !== false) {
|
|
26
|
+
nuxt.options.nitro.imports = defu(nuxt.options.nitro.imports, {
|
|
27
|
+
presets: [
|
|
28
|
+
{
|
|
29
|
+
from: resolver.resolve("./runtime/server/utils/oauth"),
|
|
30
|
+
imports: ["oauth"]
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
from: resolver.resolve("./runtime/server/utils/session"),
|
|
34
|
+
imports: [
|
|
35
|
+
"getUserSession",
|
|
36
|
+
"setUserSession",
|
|
37
|
+
"clearUserSession",
|
|
38
|
+
"requireUserSession"
|
|
39
|
+
]
|
|
40
|
+
}
|
|
41
|
+
]
|
|
42
|
+
});
|
|
43
|
+
}
|
|
25
44
|
addServerHandler({
|
|
26
45
|
handler: resolver.resolve("./runtime/server/api/session.delete"),
|
|
27
46
|
route: "/api/_auth/session",
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<
|
|
1
|
+
declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<UserSession>>;
|
|
2
2
|
export default _default;
|
|
@@ -2,6 +2,7 @@ import { eventHandler, createError, getQuery, getRequestURL, sendRedirect } from
|
|
|
2
2
|
import { ofetch } from "ofetch";
|
|
3
3
|
import { withQuery } from "ufo";
|
|
4
4
|
import { defu } from "defu";
|
|
5
|
+
import { useRuntimeConfig } from "#imports";
|
|
5
6
|
export function githubEventHandler({ config, onSuccess, onError }) {
|
|
6
7
|
return eventHandler(async (event) => {
|
|
7
8
|
config = defu(config, useRuntimeConfig(event).oauth?.github, {
|
|
@@ -2,6 +2,7 @@ import { eventHandler, createError, getQuery, getRequestURL, sendRedirect } from
|
|
|
2
2
|
import { withQuery, parsePath } from "ufo";
|
|
3
3
|
import { ofetch } from "ofetch";
|
|
4
4
|
import { defu } from "defu";
|
|
5
|
+
import { useRuntimeConfig } from "#imports";
|
|
5
6
|
export function spotifyEventHandler({ config, onSuccess, onError }) {
|
|
6
7
|
return eventHandler(async (event) => {
|
|
7
8
|
config = defu(config, useRuntimeConfig(event).oauth?.spotify, {
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import type { H3Event } from 'h3';
|
|
2
|
-
|
|
3
|
-
user?: any;
|
|
4
|
-
[key: string]: any;
|
|
5
|
-
}
|
|
2
|
+
import type { UserSession } from '#auth-utils';
|
|
6
3
|
export declare function getUserSession(event: H3Event): Promise<UserSession>;
|
|
7
4
|
/**
|
|
8
5
|
* Set a user session
|
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-auth-utils",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "Minimalist Auth module for Nuxt with SSR",
|
|
5
5
|
"repository": "Atinux/nuxt-auth-utils",
|
|
6
6
|
"license": "MIT",
|
|
@@ -25,10 +25,12 @@
|
|
|
25
25
|
"release": "npm run lint && npm run test && npm run prepack && changelogen --release && npm publish && git push --follow-tags",
|
|
26
26
|
"lint": "eslint .",
|
|
27
27
|
"test": "vitest run",
|
|
28
|
+
"test:types": "vue-tsc --noEmit",
|
|
29
|
+
"test:types:playground": "cd playground && vue-tsc --noEmit",
|
|
28
30
|
"test:watch": "vitest watch"
|
|
29
31
|
},
|
|
30
32
|
"dependencies": {
|
|
31
|
-
"@nuxt/kit": "^3.8.
|
|
33
|
+
"@nuxt/kit": "^3.8.1",
|
|
32
34
|
"defu": "^6.1.3",
|
|
33
35
|
"ohash": "^1.1.3"
|
|
34
36
|
},
|
|
@@ -37,14 +39,16 @@
|
|
|
37
39
|
"@nuxt/devtools": "latest",
|
|
38
40
|
"@nuxt/eslint-config": "^0.2.0",
|
|
39
41
|
"@nuxt/module-builder": "^0.5.2",
|
|
40
|
-
"@nuxt/schema": "^3.8.
|
|
41
|
-
"@nuxt/test-utils": "^3.8.
|
|
42
|
+
"@nuxt/schema": "^3.8.1",
|
|
43
|
+
"@nuxt/test-utils": "^3.8.1",
|
|
42
44
|
"@nuxt/ui": "^2.10.0",
|
|
43
45
|
"@nuxt/ui-pro": "^0.4.2",
|
|
44
46
|
"@types/node": "^20.8.9",
|
|
45
47
|
"changelogen": "^0.5.5",
|
|
46
48
|
"eslint": "^8.52.0",
|
|
47
|
-
"nuxt": "^3.8.
|
|
48
|
-
"
|
|
49
|
+
"nuxt": "^3.8.1",
|
|
50
|
+
"typescript": "^5.2.2",
|
|
51
|
+
"vitest": "^0.33.0",
|
|
52
|
+
"vue-tsc": "^1.8.22"
|
|
49
53
|
}
|
|
50
54
|
}
|