@lumoauth/react 1.0.0 → 1.2.0
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/README.md +421 -569
- package/dist/index.d.mts +25 -17
- package/dist/index.d.ts +25 -17
- package/dist/index.js +44 -17
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +44 -17
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -1
package/dist/index.mjs
CHANGED
|
@@ -886,12 +886,14 @@ function parseUserFromUserInfo(data) {
|
|
|
886
886
|
claims: data
|
|
887
887
|
};
|
|
888
888
|
}
|
|
889
|
+
var DEFAULT_SCOPE = "openid profile email";
|
|
889
890
|
function LumoAuthProvider({
|
|
890
891
|
domain,
|
|
891
892
|
orgId,
|
|
892
893
|
clientId,
|
|
893
894
|
authStrategy = "pkce",
|
|
894
895
|
redirectUri,
|
|
896
|
+
scope = DEFAULT_SCOPE,
|
|
895
897
|
afterSignInUrl,
|
|
896
898
|
afterSignUpUrl,
|
|
897
899
|
afterSignOutUrl,
|
|
@@ -978,18 +980,18 @@ function LumoAuthProvider({
|
|
|
978
980
|
const signInWithRedirect = useCallback(() => {
|
|
979
981
|
authModule.buildAuthorizationUrl({
|
|
980
982
|
redirectUri: resolvedRedirectUri,
|
|
981
|
-
scope
|
|
983
|
+
scope
|
|
982
984
|
}).then(({ url, codeVerifier, state: stateParam }) => {
|
|
983
985
|
savePkceParams(codeVerifier, stateParam);
|
|
984
986
|
if (typeof window !== "undefined") {
|
|
985
987
|
window.location.href = url;
|
|
986
988
|
}
|
|
987
989
|
});
|
|
988
|
-
}, [authModule, resolvedRedirectUri]);
|
|
990
|
+
}, [authModule, resolvedRedirectUri, scope]);
|
|
989
991
|
const signInWithSocial = useCallback((provider) => {
|
|
990
992
|
authModule.buildAuthorizationUrl({
|
|
991
993
|
redirectUri: resolvedRedirectUri,
|
|
992
|
-
scope
|
|
994
|
+
scope,
|
|
993
995
|
extraParams: { provider }
|
|
994
996
|
}).then(({ url, codeVerifier, state: stateParam }) => {
|
|
995
997
|
savePkceParams(codeVerifier, stateParam);
|
|
@@ -997,7 +999,7 @@ function LumoAuthProvider({
|
|
|
997
999
|
window.location.href = url;
|
|
998
1000
|
}
|
|
999
1001
|
});
|
|
1000
|
-
}, [authModule, resolvedRedirectUri]);
|
|
1002
|
+
}, [authModule, resolvedRedirectUri, scope]);
|
|
1001
1003
|
const signIn = useCallback(async (email, password) => {
|
|
1002
1004
|
if (authStrategy === "pkce" || !email && !password) {
|
|
1003
1005
|
signInWithRedirect();
|
|
@@ -1011,7 +1013,7 @@ function LumoAuthProvider({
|
|
|
1011
1013
|
const data = await authModule.passwordGrant(
|
|
1012
1014
|
email,
|
|
1013
1015
|
password,
|
|
1014
|
-
|
|
1016
|
+
scope,
|
|
1015
1017
|
redirectUri
|
|
1016
1018
|
);
|
|
1017
1019
|
await session.adopt(data);
|
|
@@ -1021,7 +1023,7 @@ function LumoAuthProvider({
|
|
|
1021
1023
|
dispatch({ type: "ERROR", error: err instanceof Error ? err.message : "Sign in failed" });
|
|
1022
1024
|
throw err;
|
|
1023
1025
|
}
|
|
1024
|
-
}, [authStrategy, authModule, redirectUri, fetchUser, session, signInWithRedirect, dispatch]);
|
|
1026
|
+
}, [authStrategy, authModule, redirectUri, scope, fetchUser, session, signInWithRedirect, dispatch]);
|
|
1025
1027
|
const handleCallback = useCallback(async () => {
|
|
1026
1028
|
if (typeof window === "undefined") return;
|
|
1027
1029
|
const params = new URLSearchParams(window.location.search);
|
|
@@ -1086,7 +1088,7 @@ function LumoAuthProvider({
|
|
|
1086
1088
|
client_id: clientId,
|
|
1087
1089
|
redirect_uri: resolvedRedirectUri,
|
|
1088
1090
|
response_type: "code",
|
|
1089
|
-
scope
|
|
1091
|
+
scope
|
|
1090
1092
|
}).toString();
|
|
1091
1093
|
if (typeof window !== "undefined") {
|
|
1092
1094
|
window.location.href = signUpUrl;
|
|
@@ -1100,7 +1102,7 @@ function LumoAuthProvider({
|
|
|
1100
1102
|
throw new Error(
|
|
1101
1103
|
`Inline registration is not supported by this LumoAuth server: there is no JSON registration endpoint. Use redirectToSignUp() to send the user to the hosted registration page (${domain.replace(/\/+$/, "")}/orgs/${encodeURIComponent(orgId)}/register), or set authStrategy: "pkce".`
|
|
1102
1104
|
);
|
|
1103
|
-
}, [authStrategy, domain, orgId, clientId, resolvedRedirectUri, signIn]);
|
|
1105
|
+
}, [authStrategy, domain, orgId, clientId, resolvedRedirectUri, scope, signIn]);
|
|
1104
1106
|
const sendMagicLink = useCallback(async (email, redirectUri2) => {
|
|
1105
1107
|
await authModule.requestMagicLink({ email, redirectUri: redirectUri2 });
|
|
1106
1108
|
}, [authModule]);
|
|
@@ -2227,7 +2229,7 @@ function Protect({
|
|
|
2227
2229
|
fallback = null,
|
|
2228
2230
|
children
|
|
2229
2231
|
}) {
|
|
2230
|
-
const { isLoaded, isSignedIn } = useLumoAuthContext();
|
|
2232
|
+
const { isLoaded, isSignedIn, user } = useLumoAuthContext();
|
|
2231
2233
|
if (permission) {
|
|
2232
2234
|
return /* @__PURE__ */ jsx8(
|
|
2233
2235
|
ProtectWithPermission,
|
|
@@ -2248,6 +2250,7 @@ function Protect({
|
|
|
2248
2250
|
fallback,
|
|
2249
2251
|
isLoaded,
|
|
2250
2252
|
isSignedIn,
|
|
2253
|
+
user,
|
|
2251
2254
|
children
|
|
2252
2255
|
}
|
|
2253
2256
|
);
|
|
@@ -2285,25 +2288,49 @@ function ProtectWithPermission({
|
|
|
2285
2288
|
}
|
|
2286
2289
|
return /* @__PURE__ */ jsx8(Fragment3, { children });
|
|
2287
2290
|
}
|
|
2291
|
+
function resolveZanzibarSubject(explicit, user) {
|
|
2292
|
+
if (explicit) return explicit;
|
|
2293
|
+
const sub = user?.sub || user?.id;
|
|
2294
|
+
return sub ? `user:${sub}` : null;
|
|
2295
|
+
}
|
|
2288
2296
|
function ProtectWithZanzibar({
|
|
2289
2297
|
zanzibar,
|
|
2290
2298
|
fallback,
|
|
2291
2299
|
isLoaded,
|
|
2292
2300
|
isSignedIn,
|
|
2301
|
+
user,
|
|
2293
2302
|
children
|
|
2294
2303
|
}) {
|
|
2295
|
-
|
|
2296
|
-
object: zanzibar.object,
|
|
2297
|
-
relation: zanzibar.relation,
|
|
2298
|
-
subject: zanzibar.subject || "user:me"
|
|
2299
|
-
});
|
|
2300
|
-
if (!isLoaded || isLoading) {
|
|
2304
|
+
if (!isLoaded) {
|
|
2301
2305
|
return /* @__PURE__ */ jsx8("div", { className: "la-protect-loading", children: /* @__PURE__ */ jsx8("span", { className: "la-spinner" }) });
|
|
2302
2306
|
}
|
|
2303
|
-
|
|
2307
|
+
const subject = isSignedIn ? resolveZanzibarSubject(zanzibar.subject, user) : null;
|
|
2308
|
+
if (!subject) {
|
|
2304
2309
|
return /* @__PURE__ */ jsx8(Fragment3, { children: fallback });
|
|
2305
2310
|
}
|
|
2306
|
-
return /* @__PURE__ */ jsx8(
|
|
2311
|
+
return /* @__PURE__ */ jsx8(
|
|
2312
|
+
ZanzibarCheck,
|
|
2313
|
+
{
|
|
2314
|
+
object: zanzibar.object,
|
|
2315
|
+
relation: zanzibar.relation,
|
|
2316
|
+
subject,
|
|
2317
|
+
fallback,
|
|
2318
|
+
children
|
|
2319
|
+
}
|
|
2320
|
+
);
|
|
2321
|
+
}
|
|
2322
|
+
function ZanzibarCheck({
|
|
2323
|
+
object,
|
|
2324
|
+
relation,
|
|
2325
|
+
subject,
|
|
2326
|
+
fallback,
|
|
2327
|
+
children
|
|
2328
|
+
}) {
|
|
2329
|
+
const { allowed, isLoading } = useZanzibar({ object, relation, subject });
|
|
2330
|
+
if (isLoading) {
|
|
2331
|
+
return /* @__PURE__ */ jsx8("div", { className: "la-protect-loading", children: /* @__PURE__ */ jsx8("span", { className: "la-spinner" }) });
|
|
2332
|
+
}
|
|
2333
|
+
return allowed ? /* @__PURE__ */ jsx8(Fragment3, { children }) : /* @__PURE__ */ jsx8(Fragment3, { children: fallback });
|
|
2307
2334
|
}
|
|
2308
2335
|
function ProtectWithAbac({
|
|
2309
2336
|
abac,
|