@revenexx/cover 0.2.9 → 0.2.10
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.
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolve the signed-in user from the BFF for route middleware (SSR-safe).
|
|
3
|
+
*
|
|
4
|
+
* Why this forwards the brokered tenant headers, not just the cookie:
|
|
5
|
+
* on a deployed multi-tenant Site the platform entrypoint resolves the tenant
|
|
6
|
+
* from the request Host and injects `x-revenexx-tenant` + `x-revenexx-context`
|
|
7
|
+
* (the per-request gateway JWT) onto the incoming request. The BFF's SDK reads
|
|
8
|
+
* them off the request event (server/utils/revenexxSdk.ts `brokeredContext`)
|
|
9
|
+
* and there is NO env-credential fallback on a live Site.
|
|
10
|
+
*
|
|
11
|
+
* Route middleware resolves auth with an internal `$fetch("/api/auth/me")`.
|
|
12
|
+
* That internal request gets a fresh event that does NOT inherit the original
|
|
13
|
+
* navigation's headers — so forwarding only the cookie leaves auth/me with no
|
|
14
|
+
* tenant context: the SDK throws 503 "api_not_configured", me() returns null,
|
|
15
|
+
* and the guard bounces a signed-in visitor to /login on every hard SSR load
|
|
16
|
+
* (refresh, deep link, server-rendered first paint). Forwarding the brokered
|
|
17
|
+
* headers scopes the internal call to the same tenant as the navigation that
|
|
18
|
+
* triggered it. On the client useRequestHeaders() returns {} and the browser's
|
|
19
|
+
* own request already carries the cookie + hits the tenant-injecting edge, so
|
|
20
|
+
* the same call works there unchanged.
|
|
21
|
+
*/
|
|
22
|
+
export async function fetchSessionUser(): Promise<{ $id: string } | null> {
|
|
23
|
+
const headers = useRequestHeaders(["cookie", "x-revenexx-tenant", "x-revenexx-context"]);
|
|
24
|
+
return await $fetch<{ $id: string } | null>("/api/auth/me", { headers }).catch(() => null);
|
|
25
|
+
}
|
|
@@ -6,12 +6,13 @@ export default defineNuxtRouteMiddleware(async (to) => {
|
|
|
6
6
|
return;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
// Resolve the session against the BFF like guest-only
|
|
10
|
-
//
|
|
11
|
-
//
|
|
12
|
-
//
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
// Resolve the session against the BFF like guest-only does. The auth
|
|
10
|
+
// store's user is not hydrated during SSR, so store-based checks would
|
|
11
|
+
// bounce signed-in users to /login — and guest-only would bounce them
|
|
12
|
+
// straight back, looping the request. fetchSessionUser() forwards the
|
|
13
|
+
// brokered tenant headers so the internal call authenticates on a live
|
|
14
|
+
// multi-tenant Site (see useSessionUser.ts).
|
|
15
|
+
const user = await fetchSessionUser();
|
|
15
16
|
if (user) {
|
|
16
17
|
return;
|
|
17
18
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
export default defineNuxtRouteMiddleware(async () => {
|
|
2
2
|
const localePath = useLocalePath();
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
// fetchSessionUser() forwards the brokered tenant headers so the internal
|
|
5
|
+
// auth/me call resolves on a live multi-tenant Site (see useSessionUser.ts).
|
|
6
|
+
const user = await fetchSessionUser();
|
|
6
7
|
if (user) {
|
|
7
8
|
return navigateTo(localePath("/account"));
|
|
8
9
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@revenexx/cover",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.10",
|
|
4
4
|
"description": "Cover — revenexx design system for Nuxt. Distributed as a Nuxt layer: generic UI components, theming tokens and stores shared by the demo shop, custom storefronts and the Blokkli theme.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./nuxt.config.ts",
|