@pramen/cms-editor 0.0.55 → 0.0.56

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pramen/cms-editor",
3
- "version": "0.0.55",
3
+ "version": "0.0.56",
4
4
  "description": "Visual block/page editor for @pramen/cms \u2014 a standalone React SPA that talks to the CMS handlers over HTTP.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -64,6 +64,27 @@ export interface Me {
64
64
  [k: string]: JsonValue | undefined;
65
65
  }
66
66
 
67
+ /**
68
+ * Whether the SERVER accepted this session — the answer to `me`, which is the identity it
69
+ * resolved the bearer token to, or `null` when it resolved none.
70
+ *
71
+ * The editor used to decide it was signed in from the token's own `exp` claim alone, read
72
+ * client-side. That covers exactly one way to stop being signed in. Every other way — the
73
+ * signing secret rotated, the account deleted or deactivated, the token revoked onto the
74
+ * denylist, a stored token from an older deployment — leaves an unexpired `exp` on a token
75
+ * the server treats as ANONYMOUS. And anonymous is not an error here: pramen's ACL answers
76
+ * it, so the editor mounted and rendered a shell that looked signed in and was empty.
77
+ * `listContentTypes` and `listBlockTypes` 403 into swallowed catches, `me` comes back null,
78
+ * so the tabs collapse to the pre-types default and the page list shows only what the public
79
+ * can read — no error, no way back, nothing to click.
80
+ *
81
+ * `userId`, not truthiness of the object: `me` for an anonymous caller is `null` today, but
82
+ * an identity carrying no subject is the same non-answer and must not read as a session.
83
+ */
84
+ export function hasIdentity(me: Me | null | undefined): boolean {
85
+ return typeof me?.userId === "string" && me.userId !== "";
86
+ }
87
+
67
88
  interface AppContextValue {
68
89
  api: Api;
69
90
  cfg: Config;
@@ -145,7 +166,22 @@ export function AppProvider({ children }: { children: React.ReactNode }) {
145
166
  useEffect(() => {
146
167
  if (!authValid) return;
147
168
  // `me` gates the Users tab + drives Settings — a failing call is fine (leaves it {}).
148
- api.call<Me>("me").then(setMe).catch(() => setMe({}));
169
+ //
170
+ // It is also the only thing that asks the server whether this session is real, so a token
171
+ // it will not accept ends the session HERE rather than rendering an empty editor around it
172
+ // (see `hasIdentity`). A THROWN call is not that answer — a network blip or a deployment
173
+ // without auth handlers must not sign anyone out — only a successful call that resolves to
174
+ // no identity is.
175
+ api
176
+ .call<Me>("me")
177
+ .then((identity) => {
178
+ if (hasIdentity(identity)) { setMe(identity); return; }
179
+ // Same handoff the expiry poll makes: to the sign-in page when the host configured
180
+ // one, otherwise drop the token so the built-in Setup screen comes back.
181
+ if (SIGN_IN_URL) redirectToSignIn();
182
+ else { clearConfig(); setCfg((c) => ({ ...c, token: "" })); }
183
+ })
184
+ .catch(() => setMe({}));
149
185
  // Collections drive the nav + list/edit routes. An app that registers none (or an older
150
186
  // server without the handler) just leaves the nav as-is — a failure is non-fatal.
151
187
  api.call<CollectionMeta[]>("listCollections").then(setCollections).catch(() => setCollections([]));