@thunderid/nuxt 0.0.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 (116) hide show
  1. package/LICENSE +201 -0
  2. package/dist/module.d.mts +46 -0
  3. package/dist/module.json +9 -0
  4. package/dist/module.mjs +216 -0
  5. package/dist/runtime/components/ThunderIDRoot.d.ts +52 -0
  6. package/dist/runtime/components/ThunderIDRoot.js +160 -0
  7. package/dist/runtime/components/actions/SignInButton.d.ts +37 -0
  8. package/dist/runtime/components/actions/SignInButton.js +51 -0
  9. package/dist/runtime/components/actions/SignOutButton.d.ts +34 -0
  10. package/dist/runtime/components/actions/SignOutButton.js +43 -0
  11. package/dist/runtime/components/actions/SignUpButton.d.ts +33 -0
  12. package/dist/runtime/components/actions/SignUpButton.js +48 -0
  13. package/dist/runtime/components/auth/Callback.d.ts +43 -0
  14. package/dist/runtime/components/auth/Callback.js +93 -0
  15. package/dist/runtime/components/auth/SignIn.d.ts +38 -0
  16. package/dist/runtime/components/auth/SignIn.js +60 -0
  17. package/dist/runtime/components/auth/SignUp.d.ts +40 -0
  18. package/dist/runtime/components/auth/SignUp.js +79 -0
  19. package/dist/runtime/components/control/Loading.d.ts +36 -0
  20. package/dist/runtime/components/control/Loading.js +17 -0
  21. package/dist/runtime/components/control/SignedIn.d.ts +38 -0
  22. package/dist/runtime/components/control/SignedIn.js +17 -0
  23. package/dist/runtime/components/control/SignedOut.d.ts +37 -0
  24. package/dist/runtime/components/control/SignedOut.js +17 -0
  25. package/dist/runtime/components/organization/CreateOrganization.d.ts +32 -0
  26. package/dist/runtime/components/organization/CreateOrganization.js +29 -0
  27. package/dist/runtime/components/organization/Organization.d.ts +39 -0
  28. package/dist/runtime/components/organization/Organization.js +17 -0
  29. package/dist/runtime/components/organization/OrganizationList.d.ts +34 -0
  30. package/dist/runtime/components/organization/OrganizationList.js +30 -0
  31. package/dist/runtime/components/organization/OrganizationProfile.d.ts +32 -0
  32. package/dist/runtime/components/organization/OrganizationProfile.js +32 -0
  33. package/dist/runtime/components/organization/OrganizationSwitcher.d.ts +36 -0
  34. package/dist/runtime/components/organization/OrganizationSwitcher.js +26 -0
  35. package/dist/runtime/components/user/User.d.ts +38 -0
  36. package/dist/runtime/components/user/User.js +17 -0
  37. package/dist/runtime/components/user/UserDropdown.d.ts +38 -0
  38. package/dist/runtime/components/user/UserDropdown.js +45 -0
  39. package/dist/runtime/components/user/UserProfile.d.ts +35 -0
  40. package/dist/runtime/components/user/UserProfile.js +35 -0
  41. package/dist/runtime/composables/useThunderID.d.ts +38 -0
  42. package/dist/runtime/composables/useThunderID.js +73 -0
  43. package/dist/runtime/errors/error-codes.d.ts +40 -0
  44. package/dist/runtime/errors/error-codes.js +19 -0
  45. package/dist/runtime/errors/index.d.ts +19 -0
  46. package/dist/runtime/errors/index.js +2 -0
  47. package/dist/runtime/errors/thunderid-error.d.ts +47 -0
  48. package/dist/runtime/errors/thunderid-error.js +15 -0
  49. package/dist/runtime/middleware/auth.d.ts +35 -0
  50. package/dist/runtime/middleware/auth.js +2 -0
  51. package/dist/runtime/middleware/defineThunderIDMiddleware.d.ts +53 -0
  52. package/dist/runtime/middleware/defineThunderIDMiddleware.js +24 -0
  53. package/dist/runtime/plugins/thunderid.d.ts +39 -0
  54. package/dist/runtime/plugins/thunderid.js +128 -0
  55. package/dist/runtime/server/ThunderIDNuxtClient.d.ts +186 -0
  56. package/dist/runtime/server/ThunderIDNuxtClient.js +384 -0
  57. package/dist/runtime/server/index.d.ts +33 -0
  58. package/dist/runtime/server/index.js +3 -0
  59. package/dist/runtime/server/plugins/thunderid-ssr.d.ts +40 -0
  60. package/dist/runtime/server/plugins/thunderid-ssr.js +135 -0
  61. package/dist/runtime/server/routes/auth/branding/branding.get.d.ts +31 -0
  62. package/dist/runtime/server/routes/auth/branding/branding.get.js +40 -0
  63. package/dist/runtime/server/routes/auth/organizations/current.get.d.ts +29 -0
  64. package/dist/runtime/server/routes/auth/organizations/current.get.js +24 -0
  65. package/dist/runtime/server/routes/auth/organizations/id.get.d.ts +28 -0
  66. package/dist/runtime/server/routes/auth/organizations/id.get.js +28 -0
  67. package/dist/runtime/server/routes/auth/organizations/index.get.d.ts +28 -0
  68. package/dist/runtime/server/routes/auth/organizations/index.get.js +24 -0
  69. package/dist/runtime/server/routes/auth/organizations/index.post.d.ts +30 -0
  70. package/dist/runtime/server/routes/auth/organizations/index.post.js +30 -0
  71. package/dist/runtime/server/routes/auth/organizations/me.get.d.ts +28 -0
  72. package/dist/runtime/server/routes/auth/organizations/me.get.js +24 -0
  73. package/dist/runtime/server/routes/auth/organizations/switch.post.d.ts +32 -0
  74. package/dist/runtime/server/routes/auth/organizations/switch.post.js +49 -0
  75. package/dist/runtime/server/routes/auth/session/callback.get.d.ts +27 -0
  76. package/dist/runtime/server/routes/auth/session/callback.get.js +91 -0
  77. package/dist/runtime/server/routes/auth/session/callback.post.d.ts +48 -0
  78. package/dist/runtime/server/routes/auth/session/callback.post.js +53 -0
  79. package/dist/runtime/server/routes/auth/session/session.get.d.ts +26 -0
  80. package/dist/runtime/server/routes/auth/session/session.get.js +22 -0
  81. package/dist/runtime/server/routes/auth/session/signin.get.d.ts +29 -0
  82. package/dist/runtime/server/routes/auth/session/signin.get.js +37 -0
  83. package/dist/runtime/server/routes/auth/session/signin.post.d.ts +37 -0
  84. package/dist/runtime/server/routes/auth/session/signin.post.js +102 -0
  85. package/dist/runtime/server/routes/auth/session/signout.post.d.ts +31 -0
  86. package/dist/runtime/server/routes/auth/session/signout.post.js +38 -0
  87. package/dist/runtime/server/routes/auth/session/signup.post.d.ts +36 -0
  88. package/dist/runtime/server/routes/auth/session/signup.post.js +30 -0
  89. package/dist/runtime/server/routes/auth/session/token.get.d.ts +29 -0
  90. package/dist/runtime/server/routes/auth/session/token.get.js +6 -0
  91. package/dist/runtime/server/routes/auth/user/profile.get.d.ts +29 -0
  92. package/dist/runtime/server/routes/auth/user/profile.get.js +24 -0
  93. package/dist/runtime/server/routes/auth/user/profile.patch.d.ts +35 -0
  94. package/dist/runtime/server/routes/auth/user/profile.patch.js +41 -0
  95. package/dist/runtime/server/routes/auth/user/user.get.d.ts +25 -0
  96. package/dist/runtime/server/routes/auth/user/user.get.js +21 -0
  97. package/dist/runtime/server/utils/event-context.d.ts +49 -0
  98. package/dist/runtime/server/utils/event-context.js +3 -0
  99. package/dist/runtime/server/utils/serverSession.d.ts +65 -0
  100. package/dist/runtime/server/utils/serverSession.js +44 -0
  101. package/dist/runtime/server/utils/session.d.ts +85 -0
  102. package/dist/runtime/server/utils/session.js +106 -0
  103. package/dist/runtime/server/utils/token-refresh.d.ts +42 -0
  104. package/dist/runtime/server/utils/token-refresh.js +65 -0
  105. package/dist/runtime/types.d.ts +161 -0
  106. package/dist/runtime/types.js +0 -0
  107. package/dist/runtime/utils/createRouteMatcher.d.ts +40 -0
  108. package/dist/runtime/utils/createRouteMatcher.js +7 -0
  109. package/dist/runtime/utils/index.d.ts +30 -0
  110. package/dist/runtime/utils/index.js +1 -0
  111. package/dist/runtime/utils/log.d.ts +44 -0
  112. package/dist/runtime/utils/log.js +25 -0
  113. package/dist/runtime/utils/url-validation.d.ts +49 -0
  114. package/dist/runtime/utils/url-validation.js +38 -0
  115. package/dist/types.d.mts +7 -0
  116. package/package.json +101 -0
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com).
3
+ *
4
+ * WSO2 LLC. licenses this file to you under the Apache License,
5
+ * Version 2.0 (the "License"); you may not use this file except
6
+ * in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing,
12
+ * software distributed under the License is distributed on an
13
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ * KIND, either express or implied. See the License for the
15
+ * specific language governing permissions and limitations
16
+ * under the License.
17
+ */
18
+ import { type Component } from 'vue';
19
+ /**
20
+ * Nuxt-specific UserDropdown container.
21
+ *
22
+ * Reads `user` and `signOut` from `useThunderID()` (Nuxt auto-import) and
23
+ * profile data from `useUser()`, then delegates rendering to
24
+ * {@link BaseUserDropdown} from `@thunderid/vue`.
25
+ *
26
+ * The `signOut` action comes from the Nuxt plugin's THUNDERID_KEY so it uses
27
+ * `navigateTo` for the redirect instead of `window.location`.
28
+ *
29
+ * The embedded profile modal renders the Nuxt-specific `UserProfile` so that
30
+ * profile update handlers are also wired through the Nuxt auto-import layer.
31
+ *
32
+ * @example
33
+ * ```vue
34
+ * <ThunderIDUserDropdown />
35
+ * ```
36
+ */
37
+ declare const UserDropdown: Component;
38
+ export default UserDropdown;
@@ -0,0 +1,45 @@
1
+ import { withVendorCSSClassPrefix } from "@thunderid/browser";
2
+ import { BaseUserDropdown, UserProfile as UserProfileComponent } from "@thunderid/vue";
3
+ import { defineComponent, h, ref } from "vue";
4
+ import { useThunderID, useUser } from "#imports";
5
+ const UserDropdown = defineComponent({
6
+ emits: ["profileClick"],
7
+ name: "UserDropdown",
8
+ props: {
9
+ className: { default: "", type: String }
10
+ },
11
+ setup(props, { slots, emit }) {
12
+ const { user, signOut } = useThunderID();
13
+ useUser();
14
+ const isProfileModalOpen = ref(false);
15
+ return () => h(
16
+ BaseUserDropdown,
17
+ {
18
+ class: withVendorCSSClassPrefix("user-dropdown--styled"),
19
+ className: props.className,
20
+ isProfileModalOpen: isProfileModalOpen.value,
21
+ onProfileClick: () => {
22
+ isProfileModalOpen.value = true;
23
+ emit("profileClick");
24
+ },
25
+ onProfileModalClose: () => {
26
+ isProfileModalOpen.value = false;
27
+ },
28
+ onSignOut: () => {
29
+ signOut();
30
+ },
31
+ // Inline profile content avoids creating a circular dependency on the
32
+ // Nuxt UserProfile container; UserProfileComponent from @thunderid/vue
33
+ // reads its data from the OrganizationProvider / UserProvider context
34
+ // wired up by ThunderIDRoot, so it works identically.
35
+ profileContent: isProfileModalOpen.value ? h(UserProfileComponent, {
36
+ cardLayout: false,
37
+ editable: true
38
+ }) : null,
39
+ user: user.value
40
+ },
41
+ slots
42
+ );
43
+ }
44
+ });
45
+ export default UserDropdown;
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com).
3
+ *
4
+ * WSO2 LLC. licenses this file to you under the Apache License,
5
+ * Version 2.0 (the "License"); you may not use this file except
6
+ * in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing,
12
+ * software distributed under the License is distributed on an
13
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ * KIND, either express or implied. See the License for the
15
+ * specific language governing permissions and limitations
16
+ * under the License.
17
+ */
18
+ import { type Component } from 'vue';
19
+ /**
20
+ * Nuxt-specific UserProfile container.
21
+ *
22
+ * Reads user profile data from `useUser()` (Nuxt auto-import, re-exported
23
+ * from `@thunderid/vue`) and delegates rendering to {@link BaseUserProfile}
24
+ * from `@thunderid/vue`.
25
+ *
26
+ * Preserves the same prop/slot API as the Vue SDK's `UserProfile` component
27
+ * so consumers don't need to change their templates.
28
+ *
29
+ * @example
30
+ * ```vue
31
+ * <ThunderIDUserProfile :editable="true" title="My Profile" />
32
+ * ```
33
+ */
34
+ declare const UserProfile: Component;
35
+ export default UserProfile;
@@ -0,0 +1,35 @@
1
+ import { withVendorCSSClassPrefix } from "@thunderid/browser";
2
+ import { BaseUserProfile } from "@thunderid/vue";
3
+ import { defineComponent, h } from "vue";
4
+ import { useUser } from "#imports";
5
+ const UserProfile = defineComponent({
6
+ name: "UserProfile",
7
+ props: {
8
+ cardLayout: { default: true, type: Boolean },
9
+ className: { default: "", type: String },
10
+ editable: { default: true, type: Boolean },
11
+ hideFields: { default: () => [], type: Array },
12
+ showFields: { default: () => [], type: Array },
13
+ title: { default: "Profile", type: String }
14
+ },
15
+ setup(props, { slots }) {
16
+ const { flattenedProfile, schemas, updateProfile } = useUser();
17
+ return () => h(
18
+ BaseUserProfile,
19
+ {
20
+ cardLayout: props.cardLayout,
21
+ class: withVendorCSSClassPrefix("user-profile--styled"),
22
+ className: props.className,
23
+ editable: props.editable,
24
+ flattenedProfile: flattenedProfile?.value,
25
+ hideFields: props.hideFields,
26
+ onUpdate: updateProfile,
27
+ schemas: schemas?.value,
28
+ showFields: props.showFields,
29
+ title: props.title
30
+ },
31
+ slots
32
+ );
33
+ }
34
+ });
35
+ export default UserProfile;
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com).
3
+ *
4
+ * WSO2 LLC. licenses this file to you under the Apache License,
5
+ * Version 2.0 (the "License"); you may not use this file except
6
+ * in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing,
12
+ * software distributed under the License is distributed on an
13
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ * KIND, either express or implied. See the License for the
15
+ * specific language governing permissions and limitations
16
+ * under the License.
17
+ */
18
+ import { type ThunderIDContext } from '@thunderid/vue';
19
+ /**
20
+ * Nuxt-aware primary composable for ThunderID authentication.
21
+ *
22
+ * Mirrors the Next.js `useThunderID` hook: a thin wrapper over the base SDK's
23
+ * `useThunderID` that re-binds the redirect-based actions (`signIn`, `signOut`,
24
+ * `signUp`) to Nuxt's {@link navigateTo} so SSR redirects use the correct
25
+ * response mechanism instead of `window.location`.
26
+ *
27
+ * The surrounding context is guaranteed to be present by the Nuxt plugin
28
+ * (`THUNDERID_KEY`) and {@link ThunderIDRoot} (the auxiliary provider tree),
29
+ * so this composable does not carry a fallback branch.
30
+ *
31
+ * @example
32
+ * ```vue
33
+ * <script setup>
34
+ * const { isSignedIn, user, signIn, signOut } = useThunderID();
35
+ * </script>
36
+ * ```
37
+ */
38
+ export declare function useThunderID(): ThunderIDContext;
@@ -0,0 +1,73 @@
1
+ import { EmbeddedSignInFlowStatus, getRedirectBasedSignUpUrl } from "@thunderid/browser";
2
+ import { useThunderID as useThunderIDVue } from "@thunderid/vue";
3
+ import { navigateTo, useState, useRuntimeConfig } from "#app";
4
+ export function useThunderID() {
5
+ const context = useThunderIDVue();
6
+ const signIn = async (...args) => {
7
+ const arg0 = args[0];
8
+ const isEmbedded = typeof arg0 === "object" && arg0 !== null && "flowId" in arg0;
9
+ if (isEmbedded) {
10
+ const payload = arg0;
11
+ const request = args[1] ?? {};
12
+ const res = await $fetch("/api/auth/signin", {
13
+ body: { payload, request },
14
+ method: "POST"
15
+ });
16
+ if (res.data?.afterSignInUrl) {
17
+ if (import.meta.client) {
18
+ try {
19
+ const session = await $fetch("/api/auth/session");
20
+ const authState = useState("thunderid:auth");
21
+ authState.value = session;
22
+ } catch {
23
+ }
24
+ }
25
+ return {
26
+ authData: {},
27
+ flowStatus: EmbeddedSignInFlowStatus.SuccessCompleted
28
+ };
29
+ }
30
+ return res.data;
31
+ }
32
+ const options = arg0;
33
+ const returnTo = typeof options?.["returnTo"] === "string" ? options["returnTo"] : void 0;
34
+ const url = returnTo ? `/api/auth/signin?returnTo=${encodeURIComponent(returnTo)}` : "/api/auth/signin";
35
+ await navigateTo(url, { external: true });
36
+ return void 0;
37
+ };
38
+ const signOut = async () => {
39
+ const res = await $fetch("/api/auth/signout", { method: "POST" });
40
+ await navigateTo(res.redirectUrl || "/", { external: true });
41
+ };
42
+ const signUp = async (...args) => {
43
+ const payload = args[0];
44
+ if (payload && typeof payload === "object" && "flowType" in payload) {
45
+ const res = await $fetch("/api/auth/signup", {
46
+ body: { payload },
47
+ method: "POST"
48
+ });
49
+ if (res.data?.afterSignUpUrl) {
50
+ await navigateTo(res.data.afterSignUpUrl, { external: false });
51
+ return void 0;
52
+ }
53
+ return res.data;
54
+ }
55
+ const cfg = useRuntimeConfig().public.thunderid ?? {};
56
+ if (cfg.signUpUrl) {
57
+ await navigateTo(cfg.signUpUrl, { external: true });
58
+ return void 0;
59
+ }
60
+ const redirectUrl = getRedirectBasedSignUpUrl({
61
+ applicationId: cfg.applicationId,
62
+ baseUrl: cfg.baseUrl,
63
+ clientId: cfg.clientId
64
+ });
65
+ if (redirectUrl) {
66
+ await navigateTo(redirectUrl, { external: true });
67
+ return void 0;
68
+ }
69
+ await navigateTo("/sign-up", { external: false });
70
+ return void 0;
71
+ };
72
+ return { ...context, signIn, signOut, signUp };
73
+ }
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com).
3
+ *
4
+ * WSO2 LLC. licenses this file to you under the Apache License,
5
+ * Version 2.0 (the "License"); you may not use this file except
6
+ * in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing,
12
+ * software distributed under the License is distributed on an
13
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ * KIND, either express or implied. See the License for the
15
+ * specific language governing permissions and limitations
16
+ * under the License.
17
+ */
18
+ /**
19
+ * Typed error codes for the ThunderID Nuxt SDK.
20
+ * Every structured error thrown by the SDK carries one of these codes
21
+ * so callers can react to specific failure modes without string matching.
22
+ */
23
+ export declare enum ErrorCode {
24
+ ConfigMissingBaseUrl = "config/missing-base-url",
25
+ ConfigMissingClientId = "config/missing-client-id",
26
+ ConfigMissingSecret = "config/missing-session-secret",
27
+ OAuthCallbackError = "oauth/callback-error",
28
+ OAuthStateInvalid = "oauth/state-invalid",
29
+ OpenRedirectBlocked = "security/open-redirect-blocked",
30
+ OrganizationCreateFailed = "organization/create-failed",
31
+ OrganizationSwitchFailed = "organization/switch-failed",
32
+ SessionExpired = "session/expired",
33
+ SessionInvalid = "session/invalid",
34
+ SessionMissing = "session/missing",
35
+ TempSessionInvalid = "session/temp-invalid",
36
+ TokenExchangeFailed = "oauth/token-exchange-failed",
37
+ TokenRefreshFailed = "oauth/token-refresh-failed",
38
+ UserProfileFetchFailed = "scim2/user-profile-fetch-failed",
39
+ UserProfileUpdateFailed = "scim2/user-profile-update-failed"
40
+ }
@@ -0,0 +1,19 @@
1
+ export var ErrorCode = /* @__PURE__ */ ((ErrorCode2) => {
2
+ ErrorCode2["ConfigMissingBaseUrl"] = "config/missing-base-url";
3
+ ErrorCode2["ConfigMissingClientId"] = "config/missing-client-id";
4
+ ErrorCode2["ConfigMissingSecret"] = "config/missing-session-secret";
5
+ ErrorCode2["OAuthCallbackError"] = "oauth/callback-error";
6
+ ErrorCode2["OAuthStateInvalid"] = "oauth/state-invalid";
7
+ ErrorCode2["OpenRedirectBlocked"] = "security/open-redirect-blocked";
8
+ ErrorCode2["OrganizationCreateFailed"] = "organization/create-failed";
9
+ ErrorCode2["OrganizationSwitchFailed"] = "organization/switch-failed";
10
+ ErrorCode2["SessionExpired"] = "session/expired";
11
+ ErrorCode2["SessionInvalid"] = "session/invalid";
12
+ ErrorCode2["SessionMissing"] = "session/missing";
13
+ ErrorCode2["TempSessionInvalid"] = "session/temp-invalid";
14
+ ErrorCode2["TokenExchangeFailed"] = "oauth/token-exchange-failed";
15
+ ErrorCode2["TokenRefreshFailed"] = "oauth/token-refresh-failed";
16
+ ErrorCode2["UserProfileFetchFailed"] = "scim2/user-profile-fetch-failed";
17
+ ErrorCode2["UserProfileUpdateFailed"] = "scim2/user-profile-update-failed";
18
+ return ErrorCode2;
19
+ })(ErrorCode || {});
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com).
3
+ *
4
+ * WSO2 LLC. licenses this file to you under the Apache License,
5
+ * Version 2.0 (the "License"); you may not use this file except
6
+ * in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing,
12
+ * software distributed under the License is distributed on an
13
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ * KIND, either express or implied. See the License for the
15
+ * specific language governing permissions and limitations
16
+ * under the License.
17
+ */
18
+ export { ThunderIDError } from './thunderid-error.js';
19
+ export { ErrorCode } from './error-codes.js';
@@ -0,0 +1,2 @@
1
+ export { ThunderIDError } from "./thunderid-error.js";
2
+ export { ErrorCode } from "./error-codes.js";
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com).
3
+ *
4
+ * WSO2 LLC. licenses this file to you under the Apache License,
5
+ * Version 2.0 (the "License"); you may not use this file except
6
+ * in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing,
12
+ * software distributed under the License is distributed on an
13
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ * KIND, either express or implied. See the License for the
15
+ * specific language governing permissions and limitations
16
+ * under the License.
17
+ */
18
+ import { ErrorCode } from './error-codes.js';
19
+ /**
20
+ * Structured error type for the ThunderID Nuxt SDK.
21
+ *
22
+ * Every error thrown by SDK internals should be an `ThunderIDError` so
23
+ * that callers can branch on `err.code` instead of matching strings.
24
+ *
25
+ * @example
26
+ * ```ts
27
+ * try {
28
+ * const session = await requireServerSession(event);
29
+ * } catch (err) {
30
+ * if (err instanceof ThunderIDError && err.code === ErrorCode.SessionMissing) {
31
+ * throw createError({ statusCode: 401 });
32
+ * }
33
+ * throw err;
34
+ * }
35
+ * ```
36
+ */
37
+ export declare class ThunderIDError extends Error {
38
+ readonly code: ErrorCode;
39
+ readonly statusCode?: number;
40
+ readonly cause?: unknown;
41
+ readonly context?: Record<string, unknown>;
42
+ constructor(message: string, code: ErrorCode, opts?: {
43
+ cause?: unknown;
44
+ context?: Record<string, unknown>;
45
+ statusCode?: number;
46
+ });
47
+ }
@@ -0,0 +1,15 @@
1
+ export class ThunderIDError extends Error {
2
+ code;
3
+ statusCode;
4
+ cause;
5
+ context;
6
+ constructor(message, code, opts) {
7
+ super(message);
8
+ this.name = "ThunderIDError";
9
+ this.code = code;
10
+ this.statusCode = opts?.statusCode;
11
+ this.cause = opts?.cause;
12
+ this.context = opts?.context;
13
+ Object.setPrototypeOf(this, new.target.prototype);
14
+ }
15
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com).
3
+ *
4
+ * WSO2 LLC. licenses this file to you under the Apache License,
5
+ * Version 2.0 (the "License"); you may not use this file except
6
+ * in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing,
12
+ * software distributed under the License is distributed on an
13
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ * KIND, either express or implied. See the License for the
15
+ * specific language governing permissions and limitations
16
+ * under the License.
17
+ */
18
+ /**
19
+ * Named route middleware for protecting pages.
20
+ *
21
+ * Registered under the name `'auth'` by the Nuxt module, so pages can
22
+ * opt in by string reference:
23
+ *
24
+ * ```vue
25
+ * <script setup>
26
+ * definePageMeta({ middleware: ['auth'] });
27
+ * </script>
28
+ * ```
29
+ *
30
+ * Equivalent to `defineThunderIDMiddleware()` with no options: redirects
31
+ * unauthenticated users to `/api/auth/signin?returnTo=<path>`. For scope
32
+ * or organization gating, use `defineThunderIDMiddleware({ ... })` directly.
33
+ */
34
+ declare const _default: import("#app").RouteMiddleware;
35
+ export default _default;
@@ -0,0 +1,2 @@
1
+ import { defineThunderIDMiddleware } from "./defineThunderIDMiddleware.js";
2
+ export default defineThunderIDMiddleware();
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com).
3
+ *
4
+ * WSO2 LLC. licenses this file to you under the Apache License,
5
+ * Version 2.0 (the "License"); you may not use this file except
6
+ * in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing,
12
+ * software distributed under the License is distributed on an
13
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ * KIND, either express or implied. See the License for the
15
+ * specific language governing permissions and limitations
16
+ * under the License.
17
+ */
18
+ import { defineNuxtRouteMiddleware } from '#app';
19
+ export interface ThunderIDMiddlewareOptions {
20
+ /**
21
+ * The path to redirect unauthenticated (or unauthorised) requests to.
22
+ * Defaults to `'/api/auth/signin'`.
23
+ */
24
+ redirectTo?: string;
25
+ /**
26
+ * If `true`, the middleware will also require that the user has an
27
+ * `organizationId` in their session. Redirects to `redirectTo` if not.
28
+ */
29
+ requireOrganization?: boolean;
30
+ /**
31
+ * Required OAuth scopes. The middleware checks that every listed scope
32
+ * is present in the session before allowing access.
33
+ */
34
+ requireScopes?: string[];
35
+ }
36
+ /**
37
+ * Typed factory for ThunderID route middleware.
38
+ *
39
+ * Usage in a page component:
40
+ * ```vue
41
+ * <script setup>
42
+ * definePageMeta({
43
+ * middleware: [defineThunderIDMiddleware({ requireOrganization: true })]
44
+ * });
45
+ * </script>
46
+ * ```
47
+ *
48
+ * Or add it as a named middleware in `middleware/` and reference by name.
49
+ *
50
+ * The built-in `'auth'` middleware registered by this module is equivalent
51
+ * to calling `defineThunderIDMiddleware()` with no options.
52
+ */
53
+ export declare function defineThunderIDMiddleware(options?: ThunderIDMiddlewareOptions): ReturnType<typeof defineNuxtRouteMiddleware>;
@@ -0,0 +1,24 @@
1
+ import { defineNuxtRouteMiddleware, navigateTo, useState } from "#app";
2
+ const DEFAULT_REDIRECT_TO = "/api/auth/signin";
3
+ export function defineThunderIDMiddleware(options = {}) {
4
+ const { redirectTo = DEFAULT_REDIRECT_TO, requireOrganization = false, requireScopes = [] } = options;
5
+ return defineNuxtRouteMiddleware((to) => {
6
+ const authState = useState("thunderid:auth");
7
+ if (!authState.value?.isSignedIn) {
8
+ const returnTo = encodeURIComponent(to.fullPath);
9
+ return navigateTo(`${redirectTo}?returnTo=${returnTo}`, { external: true });
10
+ }
11
+ const user = authState.value.user;
12
+ if (requireOrganization && !user?.["organizationId"]) {
13
+ return navigateTo(redirectTo, { external: true });
14
+ }
15
+ if (requireScopes.length > 0) {
16
+ const sessionScopes = String(user?.["scopes"] ?? "").split(" ");
17
+ const hasAllScopes = requireScopes.every((s) => sessionScopes.includes(s));
18
+ if (!hasAllScopes) {
19
+ return navigateTo(redirectTo, { external: true });
20
+ }
21
+ }
22
+ return void 0;
23
+ });
24
+ }
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com).
3
+ *
4
+ * WSO2 LLC. licenses this file to you under the Apache License,
5
+ * Version 2.0 (the "License"); you may not use this file except
6
+ * in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing,
12
+ * software distributed under the License is distributed on an
13
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ * KIND, either express or implied. See the License for the
15
+ * specific language governing permissions and limitations
16
+ * under the License.
17
+ */
18
+ /**
19
+ * Universal Nuxt plugin (runs on both server and client) that wires up the
20
+ * ThunderID Vue SDK.
21
+ *
22
+ * Responsibilities — mirrors the split between `ThunderIDServerProvider` and
23
+ * `ThunderIDClientProvider` in the Next.js SDK:
24
+ *
25
+ * 1. **Auth state** — hydrate `useState('thunderid:auth')` from the Nitro
26
+ * plugin's `event.context.thunderid` so SSR and client agree on signed-in
27
+ * status and the user object.
28
+ * 2. **THUNDERID_KEY** — provide the primary auth context at the app level.
29
+ * Action helpers (`signIn` / `signOut` / `signUp`) use Nuxt's
30
+ * `navigateTo` so redirects work on both server and client.
31
+ * 3. **ThunderIDRoot** — register the wrapper component that mounts the rest
32
+ * of the provider tree (`I18nProvider`, `BrandingProvider`,
33
+ * `ThemeProvider`, `FlowProvider`, `UserProvider`, `OrganizationProvider`)
34
+ * so downstream composables receive real context values.
35
+ * 4. **ThunderIDPlugin (delegated)** — install the Vue SDK plugin in
36
+ * delegated mode so it skips browser-only initialisation (SSR-safe).
37
+ */
38
+ declare const _default: import("#app").Plugin<Record<string, unknown>> & import("#app").ObjectPlugin<Record<string, unknown>>;
39
+ export default _default;