@dyrected/admin 2.5.43 → 2.5.45

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/LICENSE.md CHANGED
@@ -4,7 +4,7 @@ Parameters
4
4
 
5
5
  Licensor: Dyrected
6
6
  Licensed Work: Dyrected
7
- Additional Use Grant: Commercial use is permitted as long as it is not used to provide a hosted or managed service that competes with Dyrected.
7
+ Additional Use Grant: Production use and commercial use of the Licensed Work are permitted for your own internal business operations, your own websites and applications, and client websites or applications that you build or deploy on behalf of a client, provided that you do not, without a separate commercial license from the Licensor, (a) provide the Licensed Work as a hosted or managed service to third parties, (b) embed, white-label, sublicense, or otherwise redistribute the Licensed Work as part of a multi-tenant or customer-facing SaaS, platform, or developer service, or (c) enable third parties to create, manage, or operate independent projects, sites, workspaces, or environments using the Licensed Work as a material part of the service you provide.
8
8
  Change Date: 2030-05-18
9
9
  Change License: Apache License 2.0
10
10
 
package/dist/index.mjs CHANGED
@@ -76,6 +76,7 @@ function DyrectedProvider({ children, apiKey: initialApiKey, baseUrl: initialBas
76
76
  const [siteId, setSiteId] = useState(() => initialSiteId || (typeof window !== "undefined" ? localStorage.getItem("dyrected_site_id") : null) || void 0);
77
77
  const [schemas, setSchemas] = useState(null);
78
78
  const [user, setUser] = useState(null);
79
+ const [authCollectionSlug, setAuthCollectionSlug] = useState(() => (typeof window !== "undefined" ? localStorage.getItem("dyrected_admin_auth_collection") : null) || null);
79
80
  const client = useMemo(() => {
80
81
  if (!baseUrl) return null;
81
82
  return createClient({
@@ -117,28 +118,39 @@ function DyrectedProvider({ children, apiKey: initialApiKey, baseUrl: initialBas
117
118
  setApiKey(newKey);
118
119
  setSiteId(newSiteId);
119
120
  }, []);
120
- const setToken = useCallback((token) => {
121
+ const setToken = useCallback((token, collectionSlug) => {
121
122
  if (!token) {
122
123
  localStorage.removeItem("dyrected_token");
124
+ localStorage.removeItem("dyrected_admin_auth_collection");
123
125
  if (client) client.clearToken();
126
+ setAuthCollectionSlug(null);
124
127
  setUser(null);
125
128
  return;
126
129
  }
130
+ const resolvedCollectionSlug = collectionSlug || authCollectionSlug || getAdminCollectionSlug(schemas);
127
131
  localStorage.setItem("dyrected_token", token);
132
+ if (resolvedCollectionSlug) {
133
+ localStorage.setItem("dyrected_admin_auth_collection", resolvedCollectionSlug);
134
+ setAuthCollectionSlug((prev) => prev === resolvedCollectionSlug ? prev : resolvedCollectionSlug);
135
+ }
128
136
  if (client) {
129
137
  client.setToken(token);
130
- const authCollection = getAdminCollectionSlug(schemas);
131
- if (authCollection) client.collection(authCollection).me().then((nextUser) => setUser(nextUser), () => setUser(null));
138
+ if (resolvedCollectionSlug) client.collection(resolvedCollectionSlug).me().then((nextUser) => setUser(nextUser), () => setUser(null));
132
139
  }
133
- }, [client, schemas]);
140
+ }, [
141
+ authCollectionSlug,
142
+ client,
143
+ schemas
144
+ ]);
134
145
  useEffect(() => {
135
146
  if (initialToken || !client || !schemas || user) return;
136
147
  const token = localStorage.getItem("dyrected_token");
137
- const authCollection = getAdminCollectionSlug(schemas);
138
- if (!token || !authCollection) return;
148
+ const resolvedCollectionSlug = authCollectionSlug || getAdminCollectionSlug(schemas);
149
+ if (!token || !resolvedCollectionSlug) return;
139
150
  client.setToken(token);
140
- client.collection(authCollection).me().then((nextUser) => setUser(nextUser), () => setUser(null));
151
+ client.collection(resolvedCollectionSlug).me().then((nextUser) => setUser(nextUser), () => setUser(null));
141
152
  }, [
153
+ authCollectionSlug,
142
154
  client,
143
155
  initialToken,
144
156
  schemas,
@@ -149,9 +161,11 @@ function DyrectedProvider({ children, apiKey: initialApiKey, baseUrl: initialBas
149
161
  localStorage.removeItem("dyrected_key");
150
162
  localStorage.removeItem("dyrected_site_id");
151
163
  localStorage.removeItem("dyrected_token");
164
+ localStorage.removeItem("dyrected_admin_auth_collection");
152
165
  setBaseUrl("");
153
166
  setApiKey(void 0);
154
167
  setSiteId(void 0);
168
+ setAuthCollectionSlug(null);
155
169
  setUser(null);
156
170
  setSchemas(null);
157
171
  }, []);
@@ -13139,6 +13153,7 @@ function AuthGate({ children }) {
13139
13153
  return {
13140
13154
  token: params.get("dyrectedExternalToken"),
13141
13155
  provider: params.get("dyrectedExternalProvider"),
13156
+ collection: params.get("dyrectedAdminCollection"),
13142
13157
  error: params.get("dyrectedExternalError")
13143
13158
  };
13144
13159
  }, []);
@@ -13156,10 +13171,10 @@ function AuthGate({ children }) {
13156
13171
  const exchanged = await client.exchangeAdminAuth(externalParams.provider, { token: externalParams.token });
13157
13172
  if (cancelled) return;
13158
13173
  setExternalExchangeError(null);
13159
- setToken(exchanged.token);
13174
+ setToken(exchanged.token, exchanged.collectionSlug);
13160
13175
  } else {
13161
13176
  setExternalExchangeError(null);
13162
- setToken(externalParams.token);
13177
+ setToken(externalParams.token, externalParams.collection);
13163
13178
  }
13164
13179
  } catch (error) {
13165
13180
  if (cancelled) return;
@@ -13182,6 +13197,7 @@ function AuthGate({ children }) {
13182
13197
  };
13183
13198
  }, [
13184
13199
  client,
13200
+ externalParams.collection,
13185
13201
  externalParams.provider,
13186
13202
  externalParams.token,
13187
13203
  isExternalAdminAuth,
@@ -14,7 +14,7 @@ export interface DyrectedContextType {
14
14
  isAuthenticated: boolean;
15
15
  schemas: AdminSchemas | null;
16
16
  user: AdminUser | null;
17
- setToken: (token: string) => void;
17
+ setToken: (token: string, collectionSlug?: string | null) => void;
18
18
  initialToken?: string;
19
19
  components?: AdminComponents;
20
20
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dyrected/admin",
3
- "version": "2.5.43",
3
+ "version": "2.5.45",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"
@@ -64,8 +64,8 @@
64
64
  "tailwind-merge": "^3.5.0",
65
65
  "tailwindcss-animate": "^1.0.7",
66
66
  "zod": "^3.25.76",
67
- "@dyrected/core": "^2.5.43",
68
- "@dyrected/sdk": "^2.5.43"
67
+ "@dyrected/core": "^2.5.45",
68
+ "@dyrected/sdk": "^2.5.45"
69
69
  },
70
70
  "peerDependencies": {
71
71
  "@tanstack/react-query": "^5.0.0",