@rebasepro/auth 0.0.1-canary.eae7889 → 0.0.1-canary.f81da60

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/dist/api.d.ts CHANGED
@@ -20,9 +20,9 @@ export declare function register(email: string, password: string, displayName?:
20
20
  */
21
21
  export declare function login(email: string, password: string): Promise<AuthResponse>;
22
22
  /**
23
- * Login with Google ID token
23
+ * Login with Google token (ID token or access token)
24
24
  */
25
- export declare function googleLogin(idToken: string): Promise<AuthResponse>;
25
+ export declare function googleLogin(token: string, tokenType?: "idToken" | "accessToken"): Promise<AuthResponse>;
26
26
  /**
27
27
  * Login with LinkedIn OAuth code
28
28
  */
package/dist/index.es.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { useState, useRef, useEffect, useCallback, useLayoutEffect } from "react";
2
2
  import { jsxs, jsx, Fragment } from "react/jsx-runtime";
3
- import { Menu, MenuItem, iconSize, IconButton, Typography, cls, TextField, LoadingButton, Button, CenteredView, CircularProgress, Container, Table, TableHeader, TableCell, TableBody, TableRow, Tooltip, Checkbox, getColorSchemeForSeed, Chip, Dialog, DialogTitle, DialogContent, DialogActions, MultiSelect, MultiSelectItem } from "@rebasepro/ui";
3
+ import { Menu, MenuItem, iconSize, IconButton, Button, cls, Typography, TextField, LoadingButton, CenteredView, CircularProgress, Container, Table, TableHeader, TableCell, TableBody, TableRow, Tooltip, Checkbox, getColorSchemeForSeed, Chip, Dialog, DialogTitle, DialogContent, DialogActions, MultiSelect, MultiSelectItem } from "@rebasepro/ui";
4
4
  import { MoonIcon, SunIcon, SunMoonIcon, MailIcon, ArrowLeftIcon, PlusIcon, Trash2Icon } from "lucide-react";
5
5
  import { useModeController, useTranslation, LanguageToggle, ErrorView, RebaseLogo, useRebaseRegistryDispatch, useSnackbarController, ConfirmationDialog, useAuthController } from "@rebasepro/core";
6
6
  let baseApiUrl = "";
@@ -72,11 +72,11 @@ async function login(email, password) {
72
72
  });
73
73
  return handleResponse(response);
74
74
  }
75
- async function googleLogin(idToken) {
75
+ async function googleLogin(token, tokenType = "idToken") {
76
76
  const response = await fetchWithHandling(`${baseApiUrl}/api/auth/google`, {
77
77
  method: "POST",
78
78
  headers: { "Content-Type": "application/json" },
79
- body: JSON.stringify({ idToken })
79
+ body: JSON.stringify({ [tokenType]: token })
80
80
  });
81
81
  return handleResponse(response);
82
82
  }
@@ -456,11 +456,11 @@ function useRebaseAuthController(props = {}) {
456
456
  setAuthLoading(false);
457
457
  }
458
458
  }, [handleAuthSuccess]);
459
- const googleLogin$1 = useCallback(async (idToken) => {
459
+ const googleLogin$1 = useCallback(async (token, tokenType = "idToken") => {
460
460
  setAuthLoading(true);
461
461
  setAuthProviderError(null);
462
462
  try {
463
- const response = await googleLogin(idToken);
463
+ const response = await googleLogin(token, tokenType);
464
464
  await handleAuthSuccess(response.user, response.tokens);
465
465
  } catch (error) {
466
466
  setAuthProviderError(error);
@@ -1115,7 +1115,7 @@ function RebaseLoginView({
1115
1115
  "div",
1116
1116
  {
1117
1117
  className: cls(
1118
- "relative flex items-center justify-center h-screen w-screen p-4 transition-opacity duration-500 bg-white dark:bg-surface-950",
1118
+ "relative flex items-center justify-center h-screen w-screen p-4 transition-opacity duration-500 bg-white dark:bg-surface-900",
1119
1119
  fadeIn ? "opacity-100" : "opacity-0"
1120
1120
  ),
1121
1121
  children: [
@@ -1193,22 +1193,17 @@ function RebaseLoginView({
1193
1193
  authController
1194
1194
  }
1195
1195
  ),
1196
- showRegistration && /* @__PURE__ */ jsx("div", { className: "mt-2 text-center", children: /* @__PURE__ */ jsxs(Typography, { variant: "body2", color: "secondary", children: [
1197
- "Don't have an account?",
1198
- " ",
1199
- /* @__PURE__ */ jsx(
1200
- "button",
1201
- {
1202
- type: "button",
1203
- className: cls(
1204
- "font-semibold hover:underline cursor-pointer",
1205
- "text-primary-600 dark:text-primary-400"
1206
- ),
1207
- onClick: () => switchMode("register"),
1208
- children: "Create one"
1209
- }
1210
- )
1211
- ] }) })
1196
+ showRegistration && /* @__PURE__ */ jsx(
1197
+ Button,
1198
+ {
1199
+ className: "w-full",
1200
+ variant: "filled",
1201
+ color: "primary",
1202
+ size: "large",
1203
+ onClick: () => switchMode("register"),
1204
+ children: "Create an account"
1205
+ }
1206
+ )
1212
1207
  ] }),
1213
1208
  mode === "login" && /* @__PURE__ */ jsx(
1214
1209
  LoginForm,
@@ -1269,74 +1264,75 @@ function LoginButton({
1269
1264
  }
1270
1265
  );
1271
1266
  }
1267
+ const GoogleIcon = () => /* @__PURE__ */ jsxs("svg", { viewBox: "0 0 24 24", width: "20", height: "20", children: [
1268
+ /* @__PURE__ */ jsx(
1269
+ "path",
1270
+ {
1271
+ fill: "#4285F4",
1272
+ d: "M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09z"
1273
+ }
1274
+ ),
1275
+ /* @__PURE__ */ jsx(
1276
+ "path",
1277
+ {
1278
+ fill: "#34A853",
1279
+ d: "M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z"
1280
+ }
1281
+ ),
1282
+ /* @__PURE__ */ jsx(
1283
+ "path",
1284
+ {
1285
+ fill: "#FBBC05",
1286
+ d: "M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z"
1287
+ }
1288
+ ),
1289
+ /* @__PURE__ */ jsx(
1290
+ "path",
1291
+ {
1292
+ fill: "#EA4335",
1293
+ d: "M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z"
1294
+ }
1295
+ )
1296
+ ] });
1272
1297
  function GoogleLoginButton({
1273
1298
  disabled,
1274
1299
  googleClientId,
1275
1300
  authController
1276
1301
  }) {
1277
- const handleGoogleLogin = async () => {
1278
- try {
1279
- const google = window.google;
1280
- if (!google) {
1281
- console.error("Google Sign-In not loaded");
1282
- return;
1283
- }
1284
- google.accounts.id.initialize({
1285
- client_id: googleClientId,
1286
- callback: async (response) => {
1287
- try {
1288
- await authController.googleLogin(response.credential);
1289
- } catch (err) {
1290
- console.error("Google login error:", err);
1291
- }
1302
+ const tokenClientRef = useRef(null);
1303
+ useEffect(() => {
1304
+ const google = window.google;
1305
+ if (!google || tokenClientRef.current) return;
1306
+ tokenClientRef.current = google.accounts.oauth2.initTokenClient({
1307
+ client_id: googleClientId,
1308
+ scope: "openid email profile",
1309
+ callback: async (response) => {
1310
+ if (response.error || !response.access_token) {
1311
+ console.error("Google login error:", response.error);
1312
+ return;
1292
1313
  }
1293
- });
1294
- google.accounts.id.prompt();
1295
- } catch (err) {
1296
- console.error("Google login error:", err);
1314
+ try {
1315
+ await authController.googleLogin(response.access_token, "accessToken");
1316
+ } catch (err) {
1317
+ console.error("Google login error:", err);
1318
+ }
1319
+ }
1320
+ });
1321
+ }, [googleClientId, authController]);
1322
+ const handleClick = () => {
1323
+ if (!tokenClientRef.current) {
1324
+ console.error("Google Sign-In not loaded");
1325
+ return;
1297
1326
  }
1327
+ tokenClientRef.current.requestAccessToken();
1298
1328
  };
1299
1329
  return /* @__PURE__ */ jsx(
1300
- Button,
1330
+ LoginButton,
1301
1331
  {
1302
1332
  disabled,
1303
- className: "w-full",
1304
- variant: "outlined",
1305
- size: "large",
1306
- onClick: handleGoogleLogin,
1307
- children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-center w-full gap-3 py-1", children: [
1308
- /* @__PURE__ */ jsxs("svg", { viewBox: "0 0 24 24", width: "20", height: "20", children: [
1309
- /* @__PURE__ */ jsx(
1310
- "path",
1311
- {
1312
- fill: "#4285F4",
1313
- d: "M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09z"
1314
- }
1315
- ),
1316
- /* @__PURE__ */ jsx(
1317
- "path",
1318
- {
1319
- fill: "#34A853",
1320
- d: "M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z"
1321
- }
1322
- ),
1323
- /* @__PURE__ */ jsx(
1324
- "path",
1325
- {
1326
- fill: "#FBBC05",
1327
- d: "M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z"
1328
- }
1329
- ),
1330
- /* @__PURE__ */ jsx(
1331
- "path",
1332
- {
1333
- fill: "#EA4335",
1334
- d: "M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z"
1335
- }
1336
- )
1337
- ] }),
1338
- /* @__PURE__ */ jsx(Typography, { variant: "button", children: "Continue with Google" })
1339
- ] })
1333
+ text: "Sign in with Google",
1334
+ icon: /* @__PURE__ */ jsx(GoogleIcon, {}),
1335
+ onClick: handleClick
1340
1336
  }
1341
1337
  );
1342
1338
  }
@@ -1457,6 +1453,7 @@ function LoginForm({
1457
1453
  {
1458
1454
  type: "submit",
1459
1455
  variant: "filled",
1456
+ color: "primary",
1460
1457
  className: "w-full mt-1",
1461
1458
  size: "large",
1462
1459
  loading: authController.authLoading,
@@ -1578,6 +1575,7 @@ function ForgotPasswordForm({
1578
1575
  {
1579
1576
  type: "submit",
1580
1577
  variant: "filled",
1578
+ color: "primary",
1581
1579
  className: "w-full",
1582
1580
  size: "large",
1583
1581
  loading: authController.authLoading,
@@ -1633,6 +1631,7 @@ function RoleChip({ role }) {
1633
1631
  }
1634
1632
  function UsersView({ userManagement, apiUrl, getAuthToken }) {
1635
1633
  const { users, roles, saveUser, deleteUser, loading } = userManagement;
1634
+ const usersError = "usersError" in userManagement ? userManagement.usersError : void 0;
1636
1635
  const snackbarController = useSnackbarController();
1637
1636
  const { user: loggedInUser } = useAuthController();
1638
1637
  const [dialogOpen, setDialogOpen] = useState(false);
@@ -1709,7 +1708,7 @@ function UsersView({ userManagement, apiUrl, getAuthToken }) {
1709
1708
  return /* @__PURE__ */ jsx(CenteredView, { children: /* @__PURE__ */ jsx(CircularProgress, {}) });
1710
1709
  }
1711
1710
  return /* @__PURE__ */ jsxs(Container, { className: "w-full flex flex-col py-4 gap-4", maxWidth: "6xl", children: [
1712
- !hasAdmin && loggedInUser && /* @__PURE__ */ jsxs("div", { className: "bg-yellow-100 dark:bg-yellow-900 border border-yellow-400 dark:border-yellow-700 rounded p-4 flex items-center justify-between", children: [
1711
+ !hasAdmin && !usersError && loggedInUser && /* @__PURE__ */ jsxs("div", { className: "bg-yellow-100 dark:bg-yellow-900 border border-yellow-400 dark:border-yellow-700 rounded p-4 flex items-center justify-between", children: [
1713
1712
  /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Typography, { variant: "label", className: "text-yellow-800 dark:text-yellow-200", children: "No admin users exist. You can make yourself an admin." }) }),
1714
1713
  /* @__PURE__ */ jsx(
1715
1714
  Button,
@@ -1752,7 +1751,10 @@ function UsersView({ userManagement, apiUrl, getAuthToken }) {
1752
1751
  return role ? /* @__PURE__ */ jsx(RoleChip, { role }, roleId) : /* @__PURE__ */ jsx("span", { children: roleId }, roleId);
1753
1752
  }) }) })
1754
1753
  ] }, user.uid)),
1755
- users.length === 0 && /* @__PURE__ */ jsx(TableRow, { children: /* @__PURE__ */ jsx(TableCell, { colspan: 4, children: /* @__PURE__ */ jsx(CenteredView, { className: "flex flex-col gap-4 my-8 items-center", children: /* @__PURE__ */ jsx(Typography, { variant: "label", children: "There are no users yet" }) }) }) })
1754
+ users.length === 0 && /* @__PURE__ */ jsx(TableRow, { children: /* @__PURE__ */ jsx(TableCell, { colspan: 4, children: /* @__PURE__ */ jsxs(CenteredView, { className: "flex flex-col gap-4 my-8 items-center", children: [
1755
+ /* @__PURE__ */ jsx(Typography, { variant: "label", children: usersError ? "You don't have permission to view users" : "There are no users yet" }),
1756
+ usersError && /* @__PURE__ */ jsx(Typography, { variant: "caption", className: "text-surface-500", children: "Contact an administrator if you need access to this section." })
1757
+ ] }) }) })
1756
1758
  ] })
1757
1759
  ] }) }),
1758
1760
  /* @__PURE__ */ jsx(
@@ -1909,6 +1911,7 @@ function UserDetailsForm({
1909
1911
  }
1910
1912
  function RolesView({ userManagement, collections = [] }) {
1911
1913
  const { roles, saveRole, deleteRole, loading, allowDefaultRolesCreation } = userManagement;
1914
+ const rolesError = "rolesError" in userManagement ? userManagement.rolesError : void 0;
1912
1915
  const snackbarController = useSnackbarController();
1913
1916
  const [dialogOpen, setDialogOpen] = useState(false);
1914
1917
  const [selectedRole, setSelectedRole] = useState();
@@ -2001,8 +2004,9 @@ function RolesView({ userManagement, collections = [] }) {
2001
2004
  ] }, role.id);
2002
2005
  }),
2003
2006
  roles.length === 0 && /* @__PURE__ */ jsx(TableRow, { children: /* @__PURE__ */ jsx(TableCell, { colspan: 4, children: /* @__PURE__ */ jsxs(CenteredView, { className: "flex flex-col gap-4 my-8 items-center", children: [
2004
- /* @__PURE__ */ jsx(Typography, { variant: "label", children: "You don't have any roles yet." }),
2005
- allowDefaultRolesCreation && /* @__PURE__ */ jsx(Button, { onClick: createDefaultRoles, children: "Create default roles" })
2007
+ /* @__PURE__ */ jsx(Typography, { variant: "label", children: rolesError ? "You don't have permission to view roles" : "You don&apos;t have any roles yet." }),
2008
+ rolesError && /* @__PURE__ */ jsx(Typography, { variant: "caption", className: "text-surface-500", children: "Contact an administrator if you need access to this section." }),
2009
+ !rolesError && allowDefaultRolesCreation && /* @__PURE__ */ jsx(Button, { onClick: createDefaultRoles, children: "Create default roles" })
2006
2010
  ] }) }) })
2007
2011
  ] })
2008
2012
  ] }) }),