@stevederico/skateboard-ui 1.2.13 → 1.2.15

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/CHANGELOG.md CHANGED
@@ -1,4 +1,8 @@
1
1
  # CHANGELOG
2
+ 1.2.14
3
+
4
+ Fix isAuthenticated validation
5
+
2
6
  1.2.13
3
7
 
4
8
  Fix CSRF localStorage sync
@@ -1,8 +1,34 @@
1
+ import { useState, useEffect } from 'react';
1
2
  import { Navigate, Outlet } from 'react-router-dom';
2
- import { isAuthenticated } from './Utilities';
3
+ import { isAuthenticated, apiRequest, getAppKey } from './Utilities';
3
4
 
4
5
  const ProtectedRoute = () => {
5
- return isAuthenticated() ? <Outlet /> : <Navigate to="/signin" replace />;
6
+ const [status, setStatus] = useState('checking'); // 'checking' | 'valid' | 'invalid'
7
+
8
+ useEffect(() => {
9
+ if (!isAuthenticated()) {
10
+ setStatus('invalid');
11
+ return;
12
+ }
13
+
14
+ // Validate session with backend
15
+ apiRequest('/me')
16
+ .then(() => setStatus('valid'))
17
+ .catch(() => {
18
+ // Clear stale localStorage data
19
+ const csrfKey = getAppKey('csrf');
20
+ const userKey = getAppKey('user');
21
+ localStorage.removeItem(csrfKey);
22
+ localStorage.removeItem(userKey);
23
+ setStatus('invalid');
24
+ });
25
+ }, []);
26
+
27
+ if (status === 'checking') {
28
+ return null; // Or a loading spinner
29
+ }
30
+
31
+ return status === 'valid' ? <Outlet /> : <Navigate to="/signin" replace />;
6
32
  };
7
33
 
8
34
  export default ProtectedRoute;
package/Utilities.js CHANGED
@@ -118,7 +118,8 @@ export function isAuthenticated() {
118
118
  return true;
119
119
  }
120
120
  const csrfKey = getAppKey('csrf');
121
- return Boolean(safeGetItem(csrfKey));
121
+ const userKey = getAppKey('user');
122
+ return Boolean(safeGetItem(csrfKey)) && Boolean(safeGetItem(userKey));
122
123
  }
123
124
 
124
125
  export function getBackendURL() {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stevederico/skateboard-ui",
3
3
  "private": false,
4
- "version": "1.2.13",
4
+ "version": "1.2.15",
5
5
  "type": "module",
6
6
  "exports": {
7
7
  "./AppSidebar": {