@witchcraft/nuxt-auth 0.5.2 → 0.6.0-beta.1

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.
Files changed (90) hide show
  1. package/README.md +188 -336
  2. package/dist/module.d.mts +64 -41
  3. package/dist/module.json +1 -1
  4. package/dist/module.mjs +25 -35
  5. package/dist/runtime/components/ExternalCallback.vue +11 -11
  6. package/dist/runtime/components/LoginProviderButtons.client.d.vue.ts +10 -15
  7. package/dist/runtime/components/LoginProviderButtons.client.vue +4 -10
  8. package/dist/runtime/components/LoginProviderButtons.client.vue.d.ts +10 -15
  9. package/dist/runtime/components/MockBypassRegistrationFields.d.vue.ts +13 -0
  10. package/dist/runtime/components/MockBypassRegistrationFields.vue +18 -0
  11. package/dist/runtime/components/MockBypassRegistrationFields.vue.d.ts +13 -0
  12. package/dist/runtime/components/Mocker.d.vue.ts +5 -1
  13. package/dist/runtime/components/Mocker.vue +7 -10
  14. package/dist/runtime/components/Mocker.vue.d.ts +5 -1
  15. package/dist/runtime/components/SessionStatus.d.vue.ts +86 -42
  16. package/dist/runtime/components/SessionStatus.vue +29 -8
  17. package/dist/runtime/components/SessionStatus.vue.d.ts +86 -42
  18. package/dist/runtime/components/UserRegistration.d.vue.ts +5 -0
  19. package/dist/runtime/components/UserRegistration.vue +2 -0
  20. package/dist/runtime/components/UserRegistration.vue.d.ts +5 -0
  21. package/dist/runtime/composables/useAuth.d.ts +382 -19
  22. package/dist/runtime/composables/useAuth.js +191 -28
  23. package/dist/runtime/composables/useAuthExternalCallback.d.ts +13 -6
  24. package/dist/runtime/composables/useAuthExternalCallback.js +27 -16
  25. package/dist/runtime/composables/useAuthExternalCode.d.ts +2 -2
  26. package/dist/runtime/composables/useAuthExternalCode.js +19 -18
  27. package/dist/runtime/composables/useAuthMocker.d.ts +11 -1
  28. package/dist/runtime/composables/useAuthMocker.js +21 -11
  29. package/dist/runtime/composables/useAuthUserRegistration.d.ts +5 -10
  30. package/dist/runtime/composables/useAuthUserRegistration.js +12 -25
  31. package/dist/runtime/core/providerStyles.js +12 -4
  32. package/dist/runtime/electron/index.d.ts +1 -0
  33. package/dist/runtime/electron/index.js +1 -0
  34. package/dist/runtime/electron/main/ElectronAuth.d.ts +123 -0
  35. package/dist/runtime/electron/main/ElectronAuth.js +200 -0
  36. package/dist/runtime/electron/main/index.d.ts +2 -0
  37. package/dist/runtime/electron/main/index.js +2 -0
  38. package/dist/runtime/electron/main/setupElectronAuthMain.d.ts +665 -0
  39. package/dist/runtime/electron/main/setupElectronAuthMain.js +137 -0
  40. package/dist/runtime/electron/preload/createElectronAuthApi.d.ts +7 -0
  41. package/dist/runtime/electron/preload/createElectronAuthApi.js +15 -0
  42. package/dist/runtime/electron/preload/index.d.ts +2 -0
  43. package/dist/runtime/electron/preload/index.js +2 -0
  44. package/dist/runtime/electron/types.d.ts +54 -0
  45. package/dist/runtime/electron/types.js +2 -0
  46. package/dist/runtime/middleware/authGlobal.js +30 -14
  47. package/dist/runtime/middleware/authProtected.js +2 -2
  48. package/dist/runtime/plugins/client/electronNuxtAuthPlugin.d.ts +48 -0
  49. package/dist/runtime/plugins/client/electronNuxtAuthPlugin.js +86 -0
  50. package/dist/runtime/plugins/client/localOnlyUsers.d.ts +25 -0
  51. package/dist/runtime/plugins/client/localOnlyUsers.js +110 -0
  52. package/dist/runtime/plugins/server/devMock.d.ts +51 -0
  53. package/dist/runtime/plugins/server/devMock.js +162 -0
  54. package/dist/runtime/server/utils/assertEventWithAuthorizedUser.d.ts +11 -0
  55. package/dist/runtime/server/utils/assertEventWithAuthorizedUser.js +10 -0
  56. package/dist/runtime/server/utils/createAuthMiddleware.d.ts +4 -4
  57. package/dist/runtime/server/utils/createAuthMiddleware.js +16 -23
  58. package/dist/runtime/server/utils/createAuthSchema.d.ts +391 -94
  59. package/dist/runtime/server/utils/createAuthSchema.js +43 -13
  60. package/dist/runtime/server/utils/createBetterAuth.d.ts +34 -0
  61. package/dist/runtime/server/utils/createBetterAuth.js +160 -0
  62. package/dist/runtime/server/utils/getBetterAuthInstance.d.ts +3 -0
  63. package/dist/runtime/server/utils/getBetterAuthInstance.js +10 -0
  64. package/dist/runtime/types.d.ts +358 -248
  65. package/dist/runtime/types.js +48 -25
  66. package/dist/runtime/utils/deserializeAuthLocalUser.d.ts +2 -0
  67. package/dist/runtime/utils/deserializeAuthLocalUser.js +9 -0
  68. package/package.json +44 -19
  69. package/dist/runtime/core/providers/github.d.ts +0 -84
  70. package/dist/runtime/core/providers/github.js +0 -55
  71. package/dist/runtime/core/providers/google.d.ts +0 -65
  72. package/dist/runtime/core/providers/google.js +0 -49
  73. package/dist/runtime/server/helpers/getSafeSecretsInfo.d.ts +0 -4
  74. package/dist/runtime/server/helpers/getSafeSecretsInfo.js +0 -10
  75. package/dist/runtime/server/helpers/logSafeRoute.d.ts +0 -1
  76. package/dist/runtime/server/helpers/logSafeRoute.js +0 -3
  77. package/dist/runtime/server/helpers/signJwt.d.ts +0 -3
  78. package/dist/runtime/server/helpers/signJwt.js +0 -16
  79. package/dist/runtime/server/helpers/verifyJwt.d.ts +0 -5
  80. package/dist/runtime/server/helpers/verifyJwt.js +0 -19
  81. package/dist/runtime/server/utils/Auth.d.ts +0 -85
  82. package/dist/runtime/server/utils/Auth.js +0 -671
  83. package/dist/runtime/server/utils/SessionManager.d.ts +0 -26
  84. package/dist/runtime/server/utils/SessionManager.js +0 -94
  85. package/dist/runtime/server/utils/createAuthHandler.d.ts +0 -9
  86. package/dist/runtime/server/utils/createAuthHandler.js +0 -29
  87. package/dist/runtime/utils/createExternalAuthLoginHandler.d.ts +0 -37
  88. package/dist/runtime/utils/createExternalAuthLoginHandler.js +0 -23
  89. package/dist/runtime/utils/getAuthApiRoute.d.ts +0 -6
  90. package/dist/runtime/utils/getAuthApiRoute.js +0 -14
@@ -3,50 +3,94 @@ type __VLS_Props = {
3
3
  /** The link to the user's profile. Links to `/users/:username` (note this is not provided by the module). */
4
4
  usernameLink?: (user: AuthUser) => string;
5
5
  };
6
- declare var __VLS_1: {
7
- user: AuthUser;
8
- authRoutes: {
9
- login: string | undefined;
10
- unauthenticated?: string | undefined;
11
- register?: string | undefined;
12
- postRegisteredLogin?: string | undefined;
13
- externalCode?: string | undefined;
14
- deeplink?: string | undefined;
15
- mockAuth?: string | undefined;
6
+ declare const __VLS_template: () => {
7
+ __VLS_Slots: {
8
+ 'authenticated-registered'?: (props: {
9
+ user: {
10
+ id: string;
11
+ email: string;
12
+ emailVerified: boolean;
13
+ name: string;
14
+ image: string | null;
15
+ isRegistered: boolean;
16
+ createdAt: Date;
17
+ updatedAt: Date;
18
+ type: "local";
19
+ username: string;
20
+ } | {
21
+ id: string;
22
+ email: string;
23
+ emailVerified: boolean;
24
+ name: string;
25
+ image: string | null;
26
+ isRegistered: boolean;
27
+ createdAt: Date;
28
+ updatedAt: Date;
29
+ username: string | null;
30
+ type?: "external" | undefined;
31
+ };
32
+ authRoutes: any;
33
+ }) => any;
34
+ } & {
35
+ user?: (props: {
36
+ user: {
37
+ id: string;
38
+ email: string;
39
+ emailVerified: boolean;
40
+ name: string;
41
+ image: string | null;
42
+ isRegistered: boolean;
43
+ createdAt: Date;
44
+ updatedAt: Date;
45
+ type: "local";
46
+ username: string;
47
+ } | {
48
+ id: string;
49
+ email: string;
50
+ emailVerified: boolean;
51
+ name: string;
52
+ image: string | null;
53
+ isRegistered: boolean;
54
+ createdAt: Date;
55
+ updatedAt: Date;
56
+ username: string | null;
57
+ type?: "external" | undefined;
58
+ };
59
+ }) => any;
60
+ } & {
61
+ 'authenticated-unregistered'?: (props: {
62
+ user: {
63
+ id: string;
64
+ email: string;
65
+ emailVerified: boolean;
66
+ name: string;
67
+ image: string | null;
68
+ isRegistered: boolean;
69
+ createdAt: Date;
70
+ updatedAt: Date;
71
+ type: "local";
72
+ username: string;
73
+ } | {
74
+ id: string;
75
+ email: string;
76
+ emailVerified: boolean;
77
+ name: string;
78
+ image: string | null;
79
+ isRegistered: boolean;
80
+ createdAt: Date;
81
+ updatedAt: Date;
82
+ username: string | null;
83
+ type?: "external" | undefined;
84
+ };
85
+ authRoutes: any;
86
+ }) => any;
87
+ } & {
88
+ unauthenticated?: (props: {
89
+ authRoutes: any;
90
+ }) => any;
16
91
  };
17
- }, __VLS_3: {
18
- user: AuthUser;
19
- }, __VLS_19: {
20
- user: AuthUser;
21
- authRoutes: {
22
- login: string | undefined;
23
- unauthenticated?: string | undefined;
24
- register?: string | undefined;
25
- postRegisteredLogin?: string | undefined;
26
- externalCode?: string | undefined;
27
- deeplink?: string | undefined;
28
- mockAuth?: string | undefined;
29
- };
30
- }, __VLS_35: {
31
- authRoutes: {
32
- login: string | undefined;
33
- unauthenticated?: string | undefined;
34
- register?: string | undefined;
35
- postRegisteredLogin?: string | undefined;
36
- externalCode?: string | undefined;
37
- deeplink?: string | undefined;
38
- mockAuth?: string | undefined;
39
- };
40
- };
41
- type __VLS_Slots = {} & {
42
- 'authenticated-registered'?: (props: typeof __VLS_1) => any;
43
- } & {
44
- user?: (props: typeof __VLS_3) => any;
45
- } & {
46
- 'authenticated-unregistered'?: (props: typeof __VLS_19) => any;
47
- } & {
48
- unauthenticated?: (props: typeof __VLS_35) => any;
49
92
  };
93
+ type __VLS_Slots = ReturnType<typeof __VLS_template>['__VLS_Slots'];
50
94
  declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
51
95
  usernameLink: (user: AuthUser) => string;
52
96
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
@@ -12,16 +12,21 @@
12
12
  :user="user"
13
13
  >
14
14
  <NuxtLink
15
+ v-if="profileLink"
15
16
  :class="`
16
17
  text-underline
17
18
  text-l
18
- ${isSemiAuthed ? 'text-red-500' : ''}
19
+ ${isExternalExpiredUser ? 'text-red-500' : ''}
19
20
  `"
20
- :title="isSemiAuthed ? 'You need to re-authenticate to use some parts of the app.' : ''"
21
- :to="usernameLink ? usernameLink(user) : defaultUsernameLink(user)"
21
+ :title="isExternalExpiredUser ? 'You need to re-authenticate to use some parts of the app.' : ''"
22
+ :to="profileLink"
23
+ @click="openInBrowser($event)"
22
24
  >
23
25
  {{ "username" in user ? user.username : user }}
24
26
  </NuxtLink>
27
+ <span v-else>
28
+ {{ "username" in user ? user.username : user }}
29
+ </span>
25
30
  </slot>
26
31
  <WButton
27
32
  :unstyle="true"
@@ -68,18 +73,34 @@
68
73
  </template>
69
74
 
70
75
  <script setup>
76
+ import { computed, useRuntimeConfig, useState } from "#imports";
71
77
  import { useAuth } from "../composables/useAuth";
78
+ import { isExpiredStateKey } from "../types.js";
72
79
  const {
73
80
  logout,
74
81
  user,
75
82
  authRoutes,
76
83
  isAuthenticated,
77
- isSemiAuthed
84
+ isExternal
78
85
  } = useAuth();
79
- function defaultUsernameLink(user2) {
80
- return isSemiAuthed.value ? useAuth().authRoutes.login : `/users/${"username" in user2 ? user2.username : ""}`;
81
- }
82
- defineProps({
86
+ const props = defineProps({
83
87
  usernameLink: { type: Function, required: false, default: void 0 }
84
88
  });
89
+ const publicServerUrl = useRuntimeConfig().public.auth.publicServerUrl;
90
+ const isExpired = useState(isExpiredStateKey, () => false);
91
+ const isExternalExpiredUser = computed(() => user.value?.type === "external" && isExpired.value);
92
+ const profileLink = computed(() => {
93
+ if (!user.value) return void 0;
94
+ const username = "username" in user.value ? user.value.username ?? "" : "";
95
+ const appPath = `/users/${username}`;
96
+ if (user.value.type === "local") return appPath;
97
+ return props.usernameLink ? props.usernameLink(user.value) : publicServerUrl && user.value.type !== void 0 ? `${publicServerUrl}/users/${username}` : appPath;
98
+ });
99
+ function openInBrowser(event) {
100
+ if (!isExternal.value || user.value?.type === "local") return;
101
+ const open = globalThis.electron?.api?.open;
102
+ if (typeof open !== "function" || !profileLink.value) return;
103
+ event.preventDefault();
104
+ open(profileLink.value);
105
+ }
85
106
  </script>
@@ -3,50 +3,94 @@ type __VLS_Props = {
3
3
  /** The link to the user's profile. Links to `/users/:username` (note this is not provided by the module). */
4
4
  usernameLink?: (user: AuthUser) => string;
5
5
  };
6
- declare var __VLS_1: {
7
- user: AuthUser;
8
- authRoutes: {
9
- login: string | undefined;
10
- unauthenticated?: string | undefined;
11
- register?: string | undefined;
12
- postRegisteredLogin?: string | undefined;
13
- externalCode?: string | undefined;
14
- deeplink?: string | undefined;
15
- mockAuth?: string | undefined;
6
+ declare const __VLS_template: () => {
7
+ __VLS_Slots: {
8
+ 'authenticated-registered'?: (props: {
9
+ user: {
10
+ id: string;
11
+ email: string;
12
+ emailVerified: boolean;
13
+ name: string;
14
+ image: string | null;
15
+ isRegistered: boolean;
16
+ createdAt: Date;
17
+ updatedAt: Date;
18
+ type: "local";
19
+ username: string;
20
+ } | {
21
+ id: string;
22
+ email: string;
23
+ emailVerified: boolean;
24
+ name: string;
25
+ image: string | null;
26
+ isRegistered: boolean;
27
+ createdAt: Date;
28
+ updatedAt: Date;
29
+ username: string | null;
30
+ type?: "external" | undefined;
31
+ };
32
+ authRoutes: any;
33
+ }) => any;
34
+ } & {
35
+ user?: (props: {
36
+ user: {
37
+ id: string;
38
+ email: string;
39
+ emailVerified: boolean;
40
+ name: string;
41
+ image: string | null;
42
+ isRegistered: boolean;
43
+ createdAt: Date;
44
+ updatedAt: Date;
45
+ type: "local";
46
+ username: string;
47
+ } | {
48
+ id: string;
49
+ email: string;
50
+ emailVerified: boolean;
51
+ name: string;
52
+ image: string | null;
53
+ isRegistered: boolean;
54
+ createdAt: Date;
55
+ updatedAt: Date;
56
+ username: string | null;
57
+ type?: "external" | undefined;
58
+ };
59
+ }) => any;
60
+ } & {
61
+ 'authenticated-unregistered'?: (props: {
62
+ user: {
63
+ id: string;
64
+ email: string;
65
+ emailVerified: boolean;
66
+ name: string;
67
+ image: string | null;
68
+ isRegistered: boolean;
69
+ createdAt: Date;
70
+ updatedAt: Date;
71
+ type: "local";
72
+ username: string;
73
+ } | {
74
+ id: string;
75
+ email: string;
76
+ emailVerified: boolean;
77
+ name: string;
78
+ image: string | null;
79
+ isRegistered: boolean;
80
+ createdAt: Date;
81
+ updatedAt: Date;
82
+ username: string | null;
83
+ type?: "external" | undefined;
84
+ };
85
+ authRoutes: any;
86
+ }) => any;
87
+ } & {
88
+ unauthenticated?: (props: {
89
+ authRoutes: any;
90
+ }) => any;
16
91
  };
17
- }, __VLS_3: {
18
- user: AuthUser;
19
- }, __VLS_19: {
20
- user: AuthUser;
21
- authRoutes: {
22
- login: string | undefined;
23
- unauthenticated?: string | undefined;
24
- register?: string | undefined;
25
- postRegisteredLogin?: string | undefined;
26
- externalCode?: string | undefined;
27
- deeplink?: string | undefined;
28
- mockAuth?: string | undefined;
29
- };
30
- }, __VLS_35: {
31
- authRoutes: {
32
- login: string | undefined;
33
- unauthenticated?: string | undefined;
34
- register?: string | undefined;
35
- postRegisteredLogin?: string | undefined;
36
- externalCode?: string | undefined;
37
- deeplink?: string | undefined;
38
- mockAuth?: string | undefined;
39
- };
40
- };
41
- type __VLS_Slots = {} & {
42
- 'authenticated-registered'?: (props: typeof __VLS_1) => any;
43
- } & {
44
- user?: (props: typeof __VLS_3) => any;
45
- } & {
46
- 'authenticated-unregistered'?: (props: typeof __VLS_19) => any;
47
- } & {
48
- unauthenticated?: (props: typeof __VLS_35) => any;
49
92
  };
93
+ type __VLS_Slots = ReturnType<typeof __VLS_template>['__VLS_Slots'];
50
94
  declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
51
95
  usernameLink: (user: AuthUser) => string;
52
96
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
@@ -1,14 +1,19 @@
1
1
  import type { StandardSchemaV1 } from "@standard-schema/spec";
2
+ import type { useAuth } from "../composables/useAuth.js";
2
3
  /**
3
4
  * @deprecated This component is deprecated and will be removed in a future version.
4
5
  */
5
6
  declare const _default: typeof __VLS_export;
6
7
  export default _default;
7
8
  declare const __VLS_export: __VLS_WithSlots<import("vue").DefineComponent<{
9
+ /** The auth instance to register against, so the app can pass one carrying its platform plugins. */
10
+ auth?: ReturnType<typeof useAuth>;
8
11
  debounce?: number;
9
12
  usernameSchema?: StandardSchemaV1<string, string>;
10
13
  id?: string;
11
14
  }, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{
15
+ /** The auth instance to register against, so the app can pass one carrying its platform plugins. */
16
+ auth?: ReturnType<typeof useAuth>;
12
17
  debounce?: number;
13
18
  usernameSchema?: StandardSchemaV1<string, string>;
14
19
  id?: string;
@@ -53,6 +53,7 @@ if (import.meta.dev) {
53
53
  console.warn("[nuxt-auth] <UserRegistration> is deprecated and will be removed in a future version.");
54
54
  }
55
55
  const props = defineProps({
56
+ auth: { type: null, required: false },
56
57
  debounce: { type: Number, required: false },
57
58
  usernameSchema: { type: Object, required: false },
58
59
  id: { type: String, required: false }
@@ -69,6 +70,7 @@ const {
69
70
  inputValid,
70
71
  isDebouncing
71
72
  } = useAuthUserRegistration({
73
+ auth: props.auth,
72
74
  debounce: props.debounce,
73
75
  usernameSchema: props.usernameSchema,
74
76
  statusTextMap: {
@@ -1,14 +1,19 @@
1
1
  import type { StandardSchemaV1 } from "@standard-schema/spec";
2
+ import type { useAuth } from "../composables/useAuth.js";
2
3
  /**
3
4
  * @deprecated This component is deprecated and will be removed in a future version.
4
5
  */
5
6
  declare const _default: typeof __VLS_export;
6
7
  export default _default;
7
8
  declare const __VLS_export: __VLS_WithSlots<import("vue").DefineComponent<{
9
+ /** The auth instance to register against, so the app can pass one carrying its platform plugins. */
10
+ auth?: ReturnType<typeof useAuth>;
8
11
  debounce?: number;
9
12
  usernameSchema?: StandardSchemaV1<string, string>;
10
13
  id?: string;
11
14
  }, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{
15
+ /** The auth instance to register against, so the app can pass one carrying its platform plugins. */
16
+ auth?: ReturnType<typeof useAuth>;
12
17
  debounce?: number;
13
18
  usernameSchema?: StandardSchemaV1<string, string>;
14
19
  id?: string;