@thunderid/nuxt 0.2.1 → 0.2.2
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/dist/module.json +1 -1
- package/dist/module.mjs +0 -46
- package/dist/runtime/components/ThunderIDRoot.d.ts +3 -7
- package/dist/runtime/components/ThunderIDRoot.js +22 -92
- package/dist/runtime/errors/error-codes.d.ts +0 -2
- package/dist/runtime/errors/error-codes.js +0 -2
- package/dist/runtime/plugins/thunderid.d.ts +2 -3
- package/dist/runtime/plugins/thunderid.js +1 -13
- package/dist/runtime/server/ThunderIDNuxtClient.d.ts +1 -8
- package/dist/runtime/server/ThunderIDNuxtClient.js +1 -83
- package/dist/runtime/server/plugins/thunderid-ssr.d.ts +1 -3
- package/dist/runtime/server/plugins/thunderid-ssr.js +2 -22
- package/dist/runtime/types.d.ts +1 -14
- package/package.json +4 -4
- package/dist/runtime/components/organization/CreateOrganization.d.ts +0 -32
- package/dist/runtime/components/organization/CreateOrganization.js +0 -29
- package/dist/runtime/components/organization/Organization.d.ts +0 -39
- package/dist/runtime/components/organization/Organization.js +0 -17
- package/dist/runtime/components/organization/OrganizationList.d.ts +0 -34
- package/dist/runtime/components/organization/OrganizationList.js +0 -30
- package/dist/runtime/components/organization/OrganizationProfile.d.ts +0 -32
- package/dist/runtime/components/organization/OrganizationProfile.js +0 -32
- package/dist/runtime/components/organization/OrganizationSwitcher.d.ts +0 -36
- package/dist/runtime/components/organization/OrganizationSwitcher.js +0 -26
- package/dist/runtime/server/routes/auth/branding/branding.get.d.ts +0 -31
- package/dist/runtime/server/routes/auth/branding/branding.get.js +0 -40
- package/dist/runtime/server/routes/auth/organizations/current.get.d.ts +0 -29
- package/dist/runtime/server/routes/auth/organizations/current.get.js +0 -24
- package/dist/runtime/server/routes/auth/organizations/id.get.d.ts +0 -28
- package/dist/runtime/server/routes/auth/organizations/id.get.js +0 -28
- package/dist/runtime/server/routes/auth/organizations/index.get.d.ts +0 -28
- package/dist/runtime/server/routes/auth/organizations/index.get.js +0 -24
- package/dist/runtime/server/routes/auth/organizations/index.post.d.ts +0 -30
- package/dist/runtime/server/routes/auth/organizations/index.post.js +0 -30
- package/dist/runtime/server/routes/auth/organizations/me.get.d.ts +0 -28
- package/dist/runtime/server/routes/auth/organizations/me.get.js +0 -24
- package/dist/runtime/server/routes/auth/organizations/switch.post.d.ts +0 -32
- package/dist/runtime/server/routes/auth/organizations/switch.post.js +0 -49
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { defineEventHandler, readBody, createError } from "h3";
|
|
2
|
-
import ThunderIDNuxtClient from "../../../ThunderIDNuxtClient.js";
|
|
3
|
-
import { verifyAndRehydrateSession } from "../../../utils/serverSession.js";
|
|
4
|
-
import { issueSessionCookie } from "../../../utils/session.js";
|
|
5
|
-
import { useRuntimeConfig } from "#imports";
|
|
6
|
-
export default defineEventHandler(async (event) => {
|
|
7
|
-
const config = useRuntimeConfig();
|
|
8
|
-
const sessionSecret = config.thunderid?.sessionSecret;
|
|
9
|
-
const session = await verifyAndRehydrateSession(
|
|
10
|
-
event,
|
|
11
|
-
sessionSecret
|
|
12
|
-
);
|
|
13
|
-
if (!session) {
|
|
14
|
-
throw createError({ statusCode: 401, statusMessage: "Unauthorized: Invalid or expired session." });
|
|
15
|
-
}
|
|
16
|
-
const { sessionId } = session;
|
|
17
|
-
let organization;
|
|
18
|
-
try {
|
|
19
|
-
const body = await readBody(event);
|
|
20
|
-
organization = body.organization;
|
|
21
|
-
} catch {
|
|
22
|
-
throw createError({ statusCode: 400, statusMessage: "Invalid request body." });
|
|
23
|
-
}
|
|
24
|
-
if (!organization?.id) {
|
|
25
|
-
throw createError({ statusCode: 400, statusMessage: "organization.id is required." });
|
|
26
|
-
}
|
|
27
|
-
let tokenResponse;
|
|
28
|
-
try {
|
|
29
|
-
const client = ThunderIDNuxtClient.getInstance();
|
|
30
|
-
const response = await client.switchOrganization(organization, sessionId);
|
|
31
|
-
tokenResponse = response;
|
|
32
|
-
} catch (err) {
|
|
33
|
-
throw createError({
|
|
34
|
-
statusCode: 500,
|
|
35
|
-
statusMessage: `Organisation switch failed: ${err instanceof Error ? err.message : String(err)}`
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
try {
|
|
39
|
-
const runtimeConfig = useRuntimeConfig();
|
|
40
|
-
const runtimeSessionSecret = runtimeConfig.thunderid?.sessionSecret;
|
|
41
|
-
await issueSessionCookie(event, sessionId, tokenResponse, runtimeSessionSecret);
|
|
42
|
-
} catch (err) {
|
|
43
|
-
throw createError({
|
|
44
|
-
statusCode: 500,
|
|
45
|
-
statusMessage: `Failed to establish new session after organisation switch: ${err instanceof Error ? err.message : String(err)}`
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
return { success: true };
|
|
49
|
-
});
|