zitejs 0.9.1 → 0.9.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.
@@ -2,9 +2,45 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useAuth = useAuth;
4
4
  exports.getCurrentUser = getCurrentUser;
5
+ const react_1 = require("react");
5
6
  function useAuth() {
6
- throw new Error('useAuth() is only available in the Zite runtime.');
7
+ const [user, setUser] = (0, react_1.useState)(null);
8
+ const [isLoading, setIsLoading] = (0, react_1.useState)(true);
9
+ (0, react_1.useEffect)(() => {
10
+ // Check if running inside the Zite sandbox (app-runtime provides auth)
11
+ const win = window;
12
+ if (typeof win._ziteGetUser === 'function') {
13
+ try {
14
+ const u = win._ziteGetUser();
15
+ setUser(u);
16
+ }
17
+ catch {
18
+ // Fall through to local dev mode
19
+ }
20
+ }
21
+ else {
22
+ // Local dev mode — return anonymous user
23
+ setUser({
24
+ id: 'local-dev',
25
+ email: 'dev@localhost',
26
+ name: 'Local Developer',
27
+ });
28
+ }
29
+ setIsLoading(false);
30
+ }, []);
31
+ return {
32
+ user,
33
+ isLoading,
34
+ authLoading: isLoading,
35
+ logout: () => {
36
+ setUser(null);
37
+ },
38
+ };
7
39
  }
8
40
  function getCurrentUser() {
9
- throw new Error('getCurrentUser() is only available in the Zite runtime.');
41
+ const win = window;
42
+ if (typeof win._ziteGetUser === 'function') {
43
+ return win._ziteGetUser();
44
+ }
45
+ return { id: 'local-dev', email: 'dev@localhost', name: 'Local Developer' };
10
46
  }
@@ -1,6 +1,42 @@
1
+ import { useState, useEffect } from 'react';
1
2
  export function useAuth() {
2
- throw new Error('useAuth() is only available in the Zite runtime.');
3
+ const [user, setUser] = useState(null);
4
+ const [isLoading, setIsLoading] = useState(true);
5
+ useEffect(() => {
6
+ // Check if running inside the Zite sandbox (app-runtime provides auth)
7
+ const win = window;
8
+ if (typeof win._ziteGetUser === 'function') {
9
+ try {
10
+ const u = win._ziteGetUser();
11
+ setUser(u);
12
+ }
13
+ catch {
14
+ // Fall through to local dev mode
15
+ }
16
+ }
17
+ else {
18
+ // Local dev mode — return anonymous user
19
+ setUser({
20
+ id: 'local-dev',
21
+ email: 'dev@localhost',
22
+ name: 'Local Developer',
23
+ });
24
+ }
25
+ setIsLoading(false);
26
+ }, []);
27
+ return {
28
+ user,
29
+ isLoading,
30
+ authLoading: isLoading,
31
+ logout: () => {
32
+ setUser(null);
33
+ },
34
+ };
3
35
  }
4
36
  export function getCurrentUser() {
5
- throw new Error('getCurrentUser() is only available in the Zite runtime.');
37
+ const win = window;
38
+ if (typeof win._ziteGetUser === 'function') {
39
+ return win._ziteGetUser();
40
+ }
41
+ return { id: 'local-dev', email: 'dev@localhost', name: 'Local Developer' };
6
42
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zitejs",
3
- "version": "0.9.1",
3
+ "version": "0.9.2",
4
4
  "description": "The Zite framework — build apps on Zite Database",
5
5
  "type": "module",
6
6
  "main": "./dist/cjs/runtime/index.js",
@@ -78,8 +78,16 @@
78
78
  "files": [
79
79
  "dist"
80
80
  ],
81
+ "peerDependencies": {
82
+ "react": ">=18"
83
+ },
84
+ "peerDependenciesMeta": {
85
+ "react": { "optional": true }
86
+ },
81
87
  "devDependencies": {
82
88
  "@types/node": "^25.9.1",
89
+ "@types/react": "^19.0.0",
90
+ "react": "^19.0.0",
83
91
  "typescript": "^5.4.0",
84
92
  "vitest": "^3.0.0"
85
93
  },