nuxt-auth-utils 0.0.2 → 0.0.3

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
@@ -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
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "auth-core",
3
3
  "configKey": "auth",
4
- "version": "0.0.2"
4
+ "version": "0.0.3"
5
5
  }
package/dist/module.mjs CHANGED
@@ -12,11 +12,14 @@ 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
25
  nuxt.options.nitro.imports = nuxt.options.nitro.imports || {};
@@ -1,2 +1,2 @@
1
- declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<import("../utils/session").UserSession>>;
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
- export interface UserSession {
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
@@ -0,0 +1,3 @@
1
+ export interface UserSession {
2
+ user?: {};
3
+ }
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-auth-utils",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
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.0",
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.0",
41
- "@nuxt/test-utils": "^3.8.0",
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.0",
48
- "vitest": "^0.33.0"
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
  }