mogh_ui 0.1.0 → 0.2.1

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.
Files changed (69) hide show
  1. package/dist/auth/index.cjs +156 -0
  2. package/dist/auth/index.cjs.map +1 -0
  3. package/dist/auth/index.d.cts +50 -0
  4. package/dist/auth/index.d.ts +50 -0
  5. package/dist/auth/index.js +115 -0
  6. package/dist/auth/index.js.map +1 -0
  7. package/dist/auth/login/header.cjs +74 -0
  8. package/dist/auth/login/header.cjs.map +1 -0
  9. package/dist/auth/login/header.d.cts +8 -0
  10. package/dist/auth/login/header.d.ts +8 -0
  11. package/dist/auth/login/header.js +60 -0
  12. package/dist/auth/login/header.js.map +1 -0
  13. package/dist/auth/login/index.cjs +245 -0
  14. package/dist/auth/login/index.cjs.map +1 -0
  15. package/dist/auth/login/index.d.cts +15 -0
  16. package/dist/auth/login/index.d.ts +15 -0
  17. package/dist/auth/login/index.js +220 -0
  18. package/dist/auth/login/index.js.map +1 -0
  19. package/dist/auth/profile/index.cjs +27 -0
  20. package/dist/auth/profile/index.cjs.map +1 -0
  21. package/dist/auth/profile/index.d.cts +5 -0
  22. package/dist/auth/profile/index.d.ts +5 -0
  23. package/dist/auth/profile/index.js +4 -0
  24. package/dist/auth/profile/index.js.map +1 -0
  25. package/dist/auth/profile/linked-logins.cjs +177 -0
  26. package/dist/auth/profile/linked-logins.cjs.map +1 -0
  27. package/dist/auth/profile/linked-logins.d.cts +13 -0
  28. package/dist/auth/profile/linked-logins.d.ts +13 -0
  29. package/dist/auth/profile/linked-logins.js +150 -0
  30. package/dist/auth/profile/linked-logins.js.map +1 -0
  31. package/dist/auth/profile/passkey.cjs +109 -0
  32. package/dist/auth/profile/passkey.cjs.map +1 -0
  33. package/dist/auth/profile/passkey.d.cts +9 -0
  34. package/dist/auth/profile/passkey.d.ts +9 -0
  35. package/dist/auth/profile/passkey.js +75 -0
  36. package/dist/auth/profile/passkey.js.map +1 -0
  37. package/dist/auth/profile/totp.cjs +147 -0
  38. package/dist/auth/profile/totp.cjs.map +1 -0
  39. package/dist/auth/profile/totp.d.cts +9 -0
  40. package/dist/auth/profile/totp.d.ts +9 -0
  41. package/dist/auth/profile/totp.js +131 -0
  42. package/dist/auth/profile/totp.js.map +1 -0
  43. package/dist/auth/utils.cjs +42 -0
  44. package/dist/auth/utils.cjs.map +1 -0
  45. package/dist/auth/utils.d.cts +4 -0
  46. package/dist/auth/utils.d.ts +4 -0
  47. package/dist/auth/utils.js +17 -0
  48. package/dist/auth/utils.js.map +1 -0
  49. package/dist/components/page-guard.d.cts +2 -2
  50. package/dist/components/page-guard.d.ts +2 -2
  51. package/dist/components/tabbed-page.cjs +3 -1
  52. package/dist/components/tabbed-page.cjs.map +1 -1
  53. package/dist/components/tabbed-page.d.cts +4 -3
  54. package/dist/components/tabbed-page.d.ts +4 -3
  55. package/dist/components/tabbed-page.js +9 -2
  56. package/dist/components/tabbed-page.js.map +1 -1
  57. package/dist/index.cjs +2 -0
  58. package/dist/index.cjs.map +1 -1
  59. package/dist/index.d.cts +9 -1
  60. package/dist/index.d.ts +9 -1
  61. package/dist/index.js +1 -0
  62. package/dist/index.js.map +1 -1
  63. package/dist/theme.cjs +12 -4
  64. package/dist/theme.cjs.map +1 -1
  65. package/dist/theme.d.cts +7 -4
  66. package/dist/theme.d.ts +7 -4
  67. package/dist/theme.js +12 -4
  68. package/dist/theme.js.map +1 -1
  69. package/package.json +7 -1
@@ -0,0 +1,156 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+ var auth_exports = {};
31
+ __export(auth_exports, {
32
+ AUTH_URL: () => AUTH_URL,
33
+ authClient: () => authClient,
34
+ setAuthUrl: () => setAuthUrl,
35
+ useAuthState: () => useAuthState,
36
+ useLogin: () => useLogin,
37
+ useLoginOptions: () => useLoginOptions,
38
+ useManageAuth: () => useManageAuth
39
+ });
40
+ module.exports = __toCommonJS(auth_exports);
41
+ var import_notifications = require("@mantine/notifications");
42
+ var import_react_query = require("@tanstack/react-query");
43
+ var MoghAuth = __toESM(require("mogh_auth_client"), 1);
44
+ var import_utils = require("./utils");
45
+ __reExport(auth_exports, require("./login"), module.exports);
46
+ __reExport(auth_exports, require("./profile"), module.exports);
47
+ __reExport(auth_exports, require("./utils"), module.exports);
48
+ let AUTH_URL;
49
+ function setAuthUrl(url) {
50
+ AUTH_URL = url;
51
+ }
52
+ function authClient() {
53
+ return MoghAuth.MoghAuthClient(AUTH_URL, MoghAuth.LOGIN_TOKENS.jwt());
54
+ }
55
+ function useLoginOptions() {
56
+ return (0, import_react_query.useQuery)({
57
+ queryKey: ["GetLoginOptions"],
58
+ queryFn: () => authClient().login("GetLoginOptions", {})
59
+ });
60
+ }
61
+ function useLogin(type, config) {
62
+ return (0, import_react_query.useMutation)({
63
+ mutationKey: [type],
64
+ mutationFn: (params) => authClient().login(type, params),
65
+ onError: (e, ...args) => {
66
+ console.log("Login error:", e);
67
+ const msg = e.result.error ?? "Unknown error. See console.";
68
+ const detail = e.result?.trace?.map((msg2) => msg2[0].toUpperCase() + msg2.slice(1)).join(" | ");
69
+ let msg_log = msg ? msg[0].toUpperCase() + msg.slice(1) + " | " : "";
70
+ if (detail) {
71
+ msg_log += detail + " | ";
72
+ }
73
+ import_notifications.notifications.show({
74
+ title: `Login request ${type} failed`,
75
+ message: `${msg_log}See console for details`,
76
+ color: "red"
77
+ });
78
+ config?.onError && config.onError(e, ...args);
79
+ },
80
+ ...config
81
+ });
82
+ }
83
+ function useManageAuth(type, config) {
84
+ return (0, import_react_query.useMutation)({
85
+ mutationKey: [type],
86
+ mutationFn: (params) => authClient().manage(type, params),
87
+ onError: (e, ...args) => {
88
+ console.log("Manage auth error:", e);
89
+ const msg = e.result.error ?? "Unknown error. See console.";
90
+ const detail = e.result?.trace?.map((msg2) => msg2[0].toUpperCase() + msg2.slice(1)).join(" | ");
91
+ let msg_log = msg ? msg[0].toUpperCase() + msg.slice(1) + " | " : "";
92
+ if (detail) {
93
+ msg_log += detail + " | ";
94
+ }
95
+ import_notifications.notifications.show({
96
+ title: `Manage auth request ${type} failed`,
97
+ message: `${msg_log}See console for details`,
98
+ color: "red"
99
+ });
100
+ config?.onError && config.onError(e, ...args);
101
+ },
102
+ ...config
103
+ });
104
+ }
105
+ let jwt_redeem_sent = false;
106
+ let passkey_sent = false;
107
+ function useAuthState() {
108
+ const onSuccess = ({ jwt }) => {
109
+ MoghAuth.LOGIN_TOKENS.add_and_change(jwt);
110
+ (0, import_utils.sanitizeQueryInner)(search);
111
+ };
112
+ const { mutate: redeemJwt } = useLogin("ExchangeForJwt", {
113
+ onSuccess
114
+ });
115
+ const { mutate: completePasskeyLogin } = useLogin("CompletePasskeyLogin", {
116
+ onSuccess
117
+ });
118
+ const search = new URLSearchParams(location.search);
119
+ const _passkey = search.get("passkey");
120
+ const passkey = _passkey ? JSON.parse(MoghAuth.Passkey.base64UrlDecode(_passkey)) : null;
121
+ if (passkey && !passkey_sent) {
122
+ navigator.credentials.get(MoghAuth.Passkey.prepareRequestChallengeResponse(passkey)).then((credential) => completePasskeyLogin({ credential })).catch((e) => {
123
+ console.error(e);
124
+ import_notifications.notifications.show({
125
+ title: "Failed to select passkey",
126
+ message: "See console for details",
127
+ color: "red"
128
+ });
129
+ });
130
+ passkey_sent = true;
131
+ }
132
+ const jwt_redeem_ready = search.get("redeem_ready") === "true";
133
+ if (jwt_redeem_ready && !jwt_redeem_sent) {
134
+ redeemJwt({});
135
+ jwt_redeem_sent = true;
136
+ }
137
+ return {
138
+ jwt_redeem_ready,
139
+ passkey_pending: !!passkey,
140
+ totp: search.get("totp") === "true"
141
+ };
142
+ }
143
+ // Annotate the CommonJS export names for ESM import in node:
144
+ 0 && (module.exports = {
145
+ AUTH_URL,
146
+ authClient,
147
+ setAuthUrl,
148
+ useAuthState,
149
+ useLogin,
150
+ useLoginOptions,
151
+ useManageAuth,
152
+ ...require("./login"),
153
+ ...require("./profile"),
154
+ ...require("./utils")
155
+ });
156
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/auth/index.ts"],"sourcesContent":["import { notifications } from \"@mantine/notifications\";\nimport {\n useMutation,\n UseMutationOptions,\n useQuery,\n} from \"@tanstack/react-query\";\nimport * as MoghAuth from \"mogh_auth_client\";\nimport { sanitizeQueryInner } from \"./utils\";\n\nexport * from \"./login\";\nexport * from \"./profile\";\nexport * from \"./utils\";\n\nexport let AUTH_URL: string;\n\n/**\n * Set the global auth url.\n * Make sure to call this before first render.\n * @param url The global url\n */\nexport function setAuthUrl(url: string) {\n AUTH_URL = url;\n}\n\nexport function authClient() {\n return MoghAuth.MoghAuthClient(AUTH_URL, MoghAuth.LOGIN_TOKENS.jwt());\n}\n\nexport function useLoginOptions() {\n return useQuery({\n queryKey: [\"GetLoginOptions\"],\n queryFn: () => authClient().login(\"GetLoginOptions\", {}),\n });\n}\n\nexport function useLogin<\n T extends MoghAuth.Types.LoginRequest[\"type\"],\n R extends Extract<MoghAuth.Types.LoginRequest, { type: T }>,\n P extends R[\"params\"],\n C extends Omit<\n UseMutationOptions<MoghAuth.LoginResponses[T], unknown, P, unknown>,\n \"mutationKey\" | \"mutationFn\"\n >,\n>(type: T, config?: C) {\n return useMutation({\n mutationKey: [type],\n mutationFn: (params: P) => authClient().login<T, R>(type, params),\n onError: (e: { result: { error?: string; trace?: string[] } }, ...args) => {\n console.log(\"Login error:\", e);\n const msg = e.result.error ?? \"Unknown error. See console.\";\n const detail = e.result?.trace\n ?.map((msg) => msg[0].toUpperCase() + msg.slice(1))\n .join(\" | \");\n let msg_log = msg ? msg[0].toUpperCase() + msg.slice(1) + \" | \" : \"\";\n if (detail) {\n msg_log += detail + \" | \";\n }\n notifications.show({\n title: `Login request ${type} failed`,\n message: `${msg_log}See console for details`,\n color: \"red\",\n });\n config?.onError && config.onError(e, ...args);\n },\n ...config,\n });\n}\n\nexport function useManageAuth<\n T extends MoghAuth.Types.ManageRequest[\"type\"],\n R extends Extract<MoghAuth.Types.ManageRequest, { type: T }>,\n P extends R[\"params\"],\n C extends Omit<\n UseMutationOptions<MoghAuth.ManageResponses[T], unknown, P, unknown>,\n \"mutationKey\" | \"mutationFn\"\n >,\n>(type: T, config?: C) {\n return useMutation({\n mutationKey: [type],\n mutationFn: (params: P) => authClient().manage<T, R>(type, params),\n onError: (e: { result: { error?: string; trace?: string[] } }, ...args) => {\n console.log(\"Manage auth error:\", e);\n const msg = e.result.error ?? \"Unknown error. See console.\";\n const detail = e.result?.trace\n ?.map((msg) => msg[0].toUpperCase() + msg.slice(1))\n .join(\" | \");\n let msg_log = msg ? msg[0].toUpperCase() + msg.slice(1) + \" | \" : \"\";\n if (detail) {\n msg_log += detail + \" | \";\n }\n notifications.show({\n title: `Manage auth request ${type} failed`,\n message: `${msg_log}See console for details`,\n color: \"red\",\n });\n config?.onError && config.onError(e, ...args);\n },\n ...config,\n });\n}\n\nlet jwt_redeem_sent = false;\nlet passkey_sent = false;\n\n/// returns whether to show login / loading screen depending on state of exchange token loop\nexport function useAuthState() {\n const onSuccess = ({ jwt }: MoghAuth.Types.JwtResponse) => {\n MoghAuth.LOGIN_TOKENS.add_and_change(jwt);\n sanitizeQueryInner(search);\n };\n const { mutate: redeemJwt } = useLogin(\"ExchangeForJwt\", {\n onSuccess,\n });\n const { mutate: completePasskeyLogin } = useLogin(\"CompletePasskeyLogin\", {\n onSuccess,\n });\n const search = new URLSearchParams(location.search);\n\n const _passkey = search.get(\"passkey\");\n const passkey = _passkey\n ? JSON.parse(MoghAuth.Passkey.base64UrlDecode(_passkey))\n : null;\n\n // guard against multiple reqs sent\n // maybe isPending would do this but not sure about with render loop, this for sure will.\n if (passkey && !passkey_sent) {\n navigator.credentials\n .get(MoghAuth.Passkey.prepareRequestChallengeResponse(passkey))\n .then((credential) => completePasskeyLogin({ credential }))\n .catch((e) => {\n console.error(e);\n notifications.show({\n title: \"Failed to select passkey\",\n message: \"See console for details\",\n color: \"red\",\n });\n });\n passkey_sent = true;\n }\n\n const jwt_redeem_ready = search.get(\"redeem_ready\") === \"true\";\n\n // guard against multiple reqs sent\n // maybe isPending would do this but not sure about with render loop, this for sure will.\n if (jwt_redeem_ready && !jwt_redeem_sent) {\n redeemJwt({});\n jwt_redeem_sent = true;\n }\n\n return {\n jwt_redeem_ready,\n passkey_pending: !!passkey,\n totp: search.get(\"totp\") === \"true\",\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,2BAA8B;AAC9B,y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AAC,CAAC,EACzD,MAAM,CAAC,MAAM;AACZ,cAAQ,MAAM,CAAC;AACf,yCAAc,KAAK;AAAA,QACjB,OAAO;AAAA,QACP,SAAS;AAAA,QACT,OAAO;AAAA,MACT,CAAC;AAAA,IACH,CAAC;AACH,mBAAe;AAAA,EACjB;AAEA,QAAM,mBAAmB,OAAO,IAAI,cAAc,MAAM;AAIxD,MAAI,oBAAoB,CAAC,iBAAiB;AACxC,cAAU,CAAC,CAAC;AACZ,sBAAkB;AAAA,EACpB;AAEA,SAAO;AAAA,IACL;AAAA,IACA,iBAAiB,CAAC,CAAC;AAAA,IACnB,MAAM,OAAO,IAAI,MAAM,MAAM;AAAA,EAC/B;AACF;","names":["msg"]}
@@ -0,0 +1,50 @@
1
+ import * as _tanstack_react_query from '@tanstack/react-query';
2
+ import { UseMutationOptions } from '@tanstack/react-query';
3
+ import * as MoghAuth from 'mogh_auth_client';
4
+ export { LoginBrandingProps, LoginPage } from './login/index.cjs';
5
+ export { LinkedLogins } from './profile/linked-logins.cjs';
6
+ export { EnrollPasskey } from './profile/passkey.cjs';
7
+ export { EnrollTotp } from './profile/totp.cjs';
8
+ export { sanitizeQuery, sanitizeQueryInner } from './utils.cjs';
9
+ import 'react/jsx-runtime';
10
+
11
+ declare let AUTH_URL: string;
12
+ /**
13
+ * Set the global auth url.
14
+ * Make sure to call this before first render.
15
+ * @param url The global url
16
+ */
17
+ declare function setAuthUrl(url: string): void;
18
+ declare function authClient(): {
19
+ login: <T extends MoghAuth.Types.LoginRequest["type"], Req extends Extract<MoghAuth.Types.LoginRequest, {
20
+ type: T;
21
+ }>>(type: T, params: Req["params"]) => Promise<MoghAuth.LoginResponses[Req["type"]]>;
22
+ manage: <T extends MoghAuth.Types.ManageRequest["type"], Req extends Extract<MoghAuth.Types.ManageRequest, {
23
+ type: T;
24
+ }>>(type: T, params: Req["params"]) => Promise<MoghAuth.ManageResponses[Req["type"]]>;
25
+ externalLogin: (provider: MoghAuth.Types.ExternalLoginProvider) => void;
26
+ };
27
+ declare function useLoginOptions(): _tanstack_react_query.UseQueryResult<MoghAuth.Types.GetLoginOptionsResponse, Error>;
28
+ declare function useLogin<T extends MoghAuth.Types.LoginRequest["type"], R extends Extract<MoghAuth.Types.LoginRequest, {
29
+ type: T;
30
+ }>, P extends R["params"], C extends Omit<UseMutationOptions<MoghAuth.LoginResponses[T], unknown, P, unknown>, "mutationKey" | "mutationFn">>(type: T, config?: C): _tanstack_react_query.UseMutationResult<MoghAuth.LoginResponses[R["type"]], {
31
+ result: {
32
+ error?: string;
33
+ trace?: string[];
34
+ };
35
+ }, P, unknown>;
36
+ declare function useManageAuth<T extends MoghAuth.Types.ManageRequest["type"], R extends Extract<MoghAuth.Types.ManageRequest, {
37
+ type: T;
38
+ }>, P extends R["params"], C extends Omit<UseMutationOptions<MoghAuth.ManageResponses[T], unknown, P, unknown>, "mutationKey" | "mutationFn">>(type: T, config?: C): _tanstack_react_query.UseMutationResult<MoghAuth.ManageResponses[R["type"]], {
39
+ result: {
40
+ error?: string;
41
+ trace?: string[];
42
+ };
43
+ }, P, unknown>;
44
+ declare function useAuthState(): {
45
+ jwt_redeem_ready: boolean;
46
+ passkey_pending: boolean;
47
+ totp: boolean;
48
+ };
49
+
50
+ export { AUTH_URL, authClient, setAuthUrl, useAuthState, useLogin, useLoginOptions, useManageAuth };
@@ -0,0 +1,50 @@
1
+ import * as _tanstack_react_query from '@tanstack/react-query';
2
+ import { UseMutationOptions } from '@tanstack/react-query';
3
+ import * as MoghAuth from 'mogh_auth_client';
4
+ export { LoginBrandingProps, LoginPage } from './login/index.js';
5
+ export { LinkedLogins } from './profile/linked-logins.js';
6
+ export { EnrollPasskey } from './profile/passkey.js';
7
+ export { EnrollTotp } from './profile/totp.js';
8
+ export { sanitizeQuery, sanitizeQueryInner } from './utils.js';
9
+ import 'react/jsx-runtime';
10
+
11
+ declare let AUTH_URL: string;
12
+ /**
13
+ * Set the global auth url.
14
+ * Make sure to call this before first render.
15
+ * @param url The global url
16
+ */
17
+ declare function setAuthUrl(url: string): void;
18
+ declare function authClient(): {
19
+ login: <T extends MoghAuth.Types.LoginRequest["type"], Req extends Extract<MoghAuth.Types.LoginRequest, {
20
+ type: T;
21
+ }>>(type: T, params: Req["params"]) => Promise<MoghAuth.LoginResponses[Req["type"]]>;
22
+ manage: <T extends MoghAuth.Types.ManageRequest["type"], Req extends Extract<MoghAuth.Types.ManageRequest, {
23
+ type: T;
24
+ }>>(type: T, params: Req["params"]) => Promise<MoghAuth.ManageResponses[Req["type"]]>;
25
+ externalLogin: (provider: MoghAuth.Types.ExternalLoginProvider) => void;
26
+ };
27
+ declare function useLoginOptions(): _tanstack_react_query.UseQueryResult<MoghAuth.Types.GetLoginOptionsResponse, Error>;
28
+ declare function useLogin<T extends MoghAuth.Types.LoginRequest["type"], R extends Extract<MoghAuth.Types.LoginRequest, {
29
+ type: T;
30
+ }>, P extends R["params"], C extends Omit<UseMutationOptions<MoghAuth.LoginResponses[T], unknown, P, unknown>, "mutationKey" | "mutationFn">>(type: T, config?: C): _tanstack_react_query.UseMutationResult<MoghAuth.LoginResponses[R["type"]], {
31
+ result: {
32
+ error?: string;
33
+ trace?: string[];
34
+ };
35
+ }, P, unknown>;
36
+ declare function useManageAuth<T extends MoghAuth.Types.ManageRequest["type"], R extends Extract<MoghAuth.Types.ManageRequest, {
37
+ type: T;
38
+ }>, P extends R["params"], C extends Omit<UseMutationOptions<MoghAuth.ManageResponses[T], unknown, P, unknown>, "mutationKey" | "mutationFn">>(type: T, config?: C): _tanstack_react_query.UseMutationResult<MoghAuth.ManageResponses[R["type"]], {
39
+ result: {
40
+ error?: string;
41
+ trace?: string[];
42
+ };
43
+ }, P, unknown>;
44
+ declare function useAuthState(): {
45
+ jwt_redeem_ready: boolean;
46
+ passkey_pending: boolean;
47
+ totp: boolean;
48
+ };
49
+
50
+ export { AUTH_URL, authClient, setAuthUrl, useAuthState, useLogin, useLoginOptions, useManageAuth };
@@ -0,0 +1,115 @@
1
+ import { notifications } from "@mantine/notifications";
2
+ import {
3
+ useMutation,
4
+ useQuery
5
+ } from "@tanstack/react-query";
6
+ import * as MoghAuth from "mogh_auth_client";
7
+ import { sanitizeQueryInner } from "./utils";
8
+ export * from "./login";
9
+ export * from "./profile";
10
+ export * from "./utils";
11
+ let AUTH_URL;
12
+ function setAuthUrl(url) {
13
+ AUTH_URL = url;
14
+ }
15
+ function authClient() {
16
+ return MoghAuth.MoghAuthClient(AUTH_URL, MoghAuth.LOGIN_TOKENS.jwt());
17
+ }
18
+ function useLoginOptions() {
19
+ return useQuery({
20
+ queryKey: ["GetLoginOptions"],
21
+ queryFn: () => authClient().login("GetLoginOptions", {})
22
+ });
23
+ }
24
+ function useLogin(type, config) {
25
+ return useMutation({
26
+ mutationKey: [type],
27
+ mutationFn: (params) => authClient().login(type, params),
28
+ onError: (e, ...args) => {
29
+ console.log("Login error:", e);
30
+ const msg = e.result.error ?? "Unknown error. See console.";
31
+ const detail = e.result?.trace?.map((msg2) => msg2[0].toUpperCase() + msg2.slice(1)).join(" | ");
32
+ let msg_log = msg ? msg[0].toUpperCase() + msg.slice(1) + " | " : "";
33
+ if (detail) {
34
+ msg_log += detail + " | ";
35
+ }
36
+ notifications.show({
37
+ title: `Login request ${type} failed`,
38
+ message: `${msg_log}See console for details`,
39
+ color: "red"
40
+ });
41
+ config?.onError && config.onError(e, ...args);
42
+ },
43
+ ...config
44
+ });
45
+ }
46
+ function useManageAuth(type, config) {
47
+ return useMutation({
48
+ mutationKey: [type],
49
+ mutationFn: (params) => authClient().manage(type, params),
50
+ onError: (e, ...args) => {
51
+ console.log("Manage auth error:", e);
52
+ const msg = e.result.error ?? "Unknown error. See console.";
53
+ const detail = e.result?.trace?.map((msg2) => msg2[0].toUpperCase() + msg2.slice(1)).join(" | ");
54
+ let msg_log = msg ? msg[0].toUpperCase() + msg.slice(1) + " | " : "";
55
+ if (detail) {
56
+ msg_log += detail + " | ";
57
+ }
58
+ notifications.show({
59
+ title: `Manage auth request ${type} failed`,
60
+ message: `${msg_log}See console for details`,
61
+ color: "red"
62
+ });
63
+ config?.onError && config.onError(e, ...args);
64
+ },
65
+ ...config
66
+ });
67
+ }
68
+ let jwt_redeem_sent = false;
69
+ let passkey_sent = false;
70
+ function useAuthState() {
71
+ const onSuccess = ({ jwt }) => {
72
+ MoghAuth.LOGIN_TOKENS.add_and_change(jwt);
73
+ sanitizeQueryInner(search);
74
+ };
75
+ const { mutate: redeemJwt } = useLogin("ExchangeForJwt", {
76
+ onSuccess
77
+ });
78
+ const { mutate: completePasskeyLogin } = useLogin("CompletePasskeyLogin", {
79
+ onSuccess
80
+ });
81
+ const search = new URLSearchParams(location.search);
82
+ const _passkey = search.get("passkey");
83
+ const passkey = _passkey ? JSON.parse(MoghAuth.Passkey.base64UrlDecode(_passkey)) : null;
84
+ if (passkey && !passkey_sent) {
85
+ navigator.credentials.get(MoghAuth.Passkey.prepareRequestChallengeResponse(passkey)).then((credential) => completePasskeyLogin({ credential })).catch((e) => {
86
+ console.error(e);
87
+ notifications.show({
88
+ title: "Failed to select passkey",
89
+ message: "See console for details",
90
+ color: "red"
91
+ });
92
+ });
93
+ passkey_sent = true;
94
+ }
95
+ const jwt_redeem_ready = search.get("redeem_ready") === "true";
96
+ if (jwt_redeem_ready && !jwt_redeem_sent) {
97
+ redeemJwt({});
98
+ jwt_redeem_sent = true;
99
+ }
100
+ return {
101
+ jwt_redeem_ready,
102
+ passkey_pending: !!passkey,
103
+ totp: search.get("totp") === "true"
104
+ };
105
+ }
106
+ export {
107
+ AUTH_URL,
108
+ authClient,
109
+ setAuthUrl,
110
+ useAuthState,
111
+ useLogin,
112
+ useLoginOptions,
113
+ useManageAuth
114
+ };
115
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/auth/index.ts"],"sourcesContent":["import { notifications } from \"@mantine/notifications\";\nimport {\n useMutation,\n UseMutationOptions,\n useQuery,\n} from \"@tanstack/react-query\";\nimport * as MoghAuth from \"mogh_auth_client\";\nimport { sanitizeQueryInner } from \"./utils\";\n\nexport * from \"./login\";\nexport * from \"./profile\";\nexport * from \"./utils\";\n\nexport let AUTH_URL: string;\n\n/**\n * Set the global auth url.\n * Make sure to call this before first render.\n * @param url The global url\n */\nexport function setAuthUrl(url: string) {\n AUTH_URL = url;\n}\n\nexport function authClient() {\n return MoghAuth.MoghAuthClient(AUTH_URL, MoghAuth.LOGIN_TOKENS.jwt());\n}\n\nexport function useLoginOptions() {\n return useQuery({\n queryKey: [\"GetLoginOptions\"],\n queryFn: () => authClient().login(\"GetLoginOptions\", {}),\n });\n}\n\nexport function useLogin<\n T extends MoghAuth.Types.LoginRequest[\"type\"],\n R extends Extract<MoghAuth.Types.LoginRequest, { type: T }>,\n P extends R[\"params\"],\n C extends Omit<\n UseMutationOptions<MoghAuth.LoginResponses[T], unknown, P, unknown>,\n \"mutationKey\" | \"mutationFn\"\n >,\n>(type: T, config?: C) {\n return useMutation({\n mutationKey: [type],\n mutationFn: (params: P) => authClient().login<T, R>(type, params),\n onError: (e: { result: { error?: string; trace?: string[] } }, ...args) => {\n console.log(\"Login error:\", e);\n const msg = e.result.error ?? \"Unknown error. See console.\";\n const detail = e.result?.trace\n ?.map((msg) => msg[0].toUpperCase() + msg.slice(1))\n .join(\" | \");\n let msg_log = msg ? msg[0].toUpperCase() + msg.slice(1) + \" | \" : \"\";\n if (detail) {\n msg_log += detail + \" | \";\n }\n notifications.show({\n title: `Login request ${type} failed`,\n message: `${msg_log}See console for details`,\n color: \"red\",\n });\n config?.onError && config.onError(e, ...args);\n },\n ...config,\n });\n}\n\nexport function useManageAuth<\n T extends MoghAuth.Types.ManageRequest[\"type\"],\n R extends Extract<MoghAuth.Types.ManageRequest, { type: T }>,\n P extends R[\"params\"],\n C extends Omit<\n UseMutationOptions<MoghAuth.ManageResponses[T], unknown, P, unknown>,\n \"mutationKey\" | \"mutationFn\"\n >,\n>(type: T, config?: C) {\n return useMutation({\n mutationKey: [type],\n mutationFn: (params: P) => authClient().manage<T, R>(type, params),\n onError: (e: { result: { error?: string; trace?: string[] } }, ...args) => {\n console.log(\"Manage auth error:\", e);\n const msg = e.result.error ?? \"Unknown error. See console.\";\n const detail = e.result?.trace\n ?.map((msg) => msg[0].toUpperCase() + msg.slice(1))\n .join(\" | \");\n let msg_log = msg ? msg[0].toUpperCase() + msg.slice(1) + \" | \" : \"\";\n if (detail) {\n msg_log += detail + \" | \";\n }\n notifications.show({\n title: `Manage auth request ${type} failed`,\n message: `${msg_log}See console for details`,\n color: \"red\",\n });\n config?.onError && config.onError(e, ...args);\n },\n ...config,\n });\n}\n\nlet jwt_redeem_sent = false;\nlet passkey_sent = false;\n\n/// returns whether to show login / loading screen depending on state of exchange token loop\nexport function useAuthState() {\n const onSuccess = ({ jwt }: MoghAuth.Types.JwtResponse) => {\n MoghAuth.LOGIN_TOKENS.add_and_change(jwt);\n sanitizeQueryInner(search);\n };\n const { mutate: redeemJwt } = useLogin(\"ExchangeForJwt\", {\n onSuccess,\n });\n const { mutate: completePasskeyLogin } = useLogin(\"CompletePasskeyLogin\", {\n onSuccess,\n });\n const search = new URLSearchParams(location.search);\n\n const _passkey = search.get(\"passkey\");\n const passkey = _passkey\n ? JSON.parse(MoghAuth.Passkey.base64UrlDecode(_passkey))\n : null;\n\n // guard against multiple reqs sent\n // maybe isPending would do this but not sure about with render loop, this for sure will.\n if (passkey && !passkey_sent) {\n navigator.credentials\n .get(MoghAuth.Passkey.prepareRequestChallengeResponse(passkey))\n .then((credential) => completePasskeyLogin({ credential }))\n .catch((e) => {\n console.error(e);\n notifications.show({\n title: \"Failed to select passkey\",\n message: \"See console for details\",\n color: \"red\",\n });\n });\n passkey_sent = true;\n }\n\n const jwt_redeem_ready = search.get(\"redeem_ready\") === \"true\";\n\n // guard against multiple reqs sent\n // maybe isPending would do this but not sure about with render loop, this for sure will.\n if (jwt_redeem_ready && !jwt_redeem_sent) {\n redeemJwt({});\n jwt_redeem_sent = true;\n }\n\n return {\n jwt_redeem_ready,\n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AAU,YACP,IAAI,SAAS,QAAQ,gCAAgC,OAAO,CAAC,EAC7D,KAAK,CAAC,eAAe,qBAAqB,EAAE,WAAW,CAAC,CAAC,EACzD,MAAM,CAAC,MAAM;AACZ,cAAQ,MAAM,CAAC;AACf,oBAAc,KAAK;AAAA,QACjB,OAAO;AAAA,QACP,SAAS;AAAA,QACT,OAAO;AAAA,MACT,CAAC;AAAA,IACH,CAAC;AACH,mBAAe;AAAA,EACjB;AAEA,QAAM,mBAAmB,OAAO,IAAI,cAAc,MAAM;AAIxD,MAAI,oBAAoB,CAAC,iBAAiB;AACxC,cAAU,CAAC,CAAC;AACZ,sBAAkB;AAAA,EACpB;AAEA,SAAO;AAAA,IACL;AAAA,IACA,iBAAiB,CAAC,CAAC;AAAA,IACnB,MAAM,OAAO,IAAI,MAAM,MAAM;AAAA,EAC/B;AACF;","names":["msg"]}
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var header_exports = {};
20
+ __export(header_exports, {
21
+ default: () => LoginHeader
22
+ });
23
+ module.exports = __toCommonJS(header_exports);
24
+ var import_jsx_runtime = require("react/jsx-runtime");
25
+ var import_core = require("@mantine/core");
26
+ var import_lucide_react = require("lucide-react");
27
+ var import__2 = require("../..");
28
+ function LoginHeader({
29
+ secondFactorPending,
30
+ appName,
31
+ iconLink,
32
+ iconLinkAlt
33
+ }) {
34
+ const options = (0, import__2.useLoginOptions)().data;
35
+ const theme = (0, import_core.useComputedColorScheme)();
36
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_core.Group, { justify: "space-between", children: [
37
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_core.Group, { gap: "sm", children: [
38
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("img", { src: iconLink, width: 42, height: 42, alt: iconLinkAlt }),
39
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_core.Stack, { gap: "0", children: [
40
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.Text, { fz: "h2", fw: "450", lts: "0.1rem", children: appName }),
41
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.Text, { size: "md", opacity: 0.6, mt: -8, children: "Log In" })
42
+ ] })
43
+ ] }),
44
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.Group, { gap: "sm", children: [
45
+ [options?.oidc, "Oidc"],
46
+ [options?.github, "Github"],
47
+ [options?.google, "Google"]
48
+ ].map(
49
+ ([enabled, provider]) => enabled && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
50
+ import_core.Button,
51
+ {
52
+ onClick: () => (0, import__2.authClient)().externalLogin(provider),
53
+ leftSection: provider === "Oidc" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_lucide_react.KeyRound, { size: "1rem" }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
54
+ "img",
55
+ {
56
+ src: `/icons/${provider.toLowerCase()}.svg`,
57
+ alt: provider,
58
+ style: {
59
+ width: "1rem",
60
+ height: "1rem",
61
+ filter: theme === "dark" ? "invert(1)" : void 0
62
+ }
63
+ }
64
+ ),
65
+ w: 110,
66
+ disabled: secondFactorPending,
67
+ children: provider
68
+ },
69
+ provider
70
+ )
71
+ ) })
72
+ ] });
73
+ }
74
+ //# sourceMappingURL=header.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/auth/login/header.tsx"],"sourcesContent":["import {\n Button,\n Group,\n Stack,\n Text,\n useComputedColorScheme,\n} from \"@mantine/core\";\nimport { KeyRound } from \"lucide-react\";\nimport * as MoghAuth from \"mogh_auth_client\";\nimport { LoginBrandingProps } from \".\";\nimport { authClient, useLoginOptions } from \"../..\";\n\nexport default function LoginHeader({\n secondFactorPending,\n appName,\n iconLink,\n iconLinkAlt,\n}: {\n secondFactorPending: boolean;\n} & LoginBrandingProps) {\n const options = useLoginOptions().data;\n const theme = useComputedColorScheme();\n return (\n <Group justify=\"space-between\">\n <Group gap=\"sm\">\n <img src={iconLink} width={42} height={42} alt={iconLinkAlt} />\n <Stack gap=\"0\">\n <Text fz=\"h2\" fw=\"450\" lts=\"0.1rem\">\n {appName}\n </Text>\n <Text size=\"md\" opacity={0.6} mt={-8}>\n Log In\n </Text>\n </Stack>\n </Group>\n <Group gap=\"sm\">\n {(\n [\n [options?.oidc, \"Oidc\"],\n [options?.github, \"Github\"],\n [options?.google, \"Google\"],\n ] as Array<\n [boolean | undefined, MoghAuth.Types.ExternalLoginProvider]\n >\n ).map(\n ([enabled, provider]) =>\n enabled && (\n <Button\n key={provider}\n onClick={() => authClient().externalLogin(provider)}\n leftSection={\n provider === \"Oidc\" ? (\n <KeyRound size=\"1rem\" />\n ) : (\n <img\n src={`/icons/${provider.toLowerCase()}.svg`}\n alt={provider}\n style={{\n width: \"1rem\",\n height: \"1rem\",\n filter: theme === \"dark\" ? \"invert(1)\" : undefined,\n }}\n />\n )\n }\n w={110}\n disabled={secondFactorPending}\n >\n {provider}\n </Button>\n ),\n )}\n </Group>\n </Group>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAyBQ;AAzBR,kBAMO;AACP,0BAAyB;AAGzB,IAAAA,YAA4C;AAE7B,SAAR,YAA6B;AAAA,EAClC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAEwB;AACtB,QAAM,cAAU,2BAAgB,EAAE;AAClC,QAAM,YAAQ,oCAAuB;AACrC,SACE,6CAAC,qBAAM,SAAQ,iBACb;AAAA,iDAAC,qBAAM,KAAI,MACT;AAAA,kDAAC,SAAI,KAAK,UAAU,OAAO,IAAI,QAAQ,IAAI,KAAK,aAAa;AAAA,MAC7D,6CAAC,qBAAM,KAAI,KACT;AAAA,oDAAC,oBAAK,IAAG,MAAK,IAAG,OAAM,KAAI,UACxB,mBACH;AAAA,QACA,4CAAC,oBAAK,MAAK,MAAK,SAAS,KAAK,IAAI,IAAI,oBAEtC;AAAA,SACF;AAAA,OACF;AAAA,IACA,4CAAC,qBAAM,KAAI,MAEP;AAAA,MACE,CAAC,SAAS,MAAM,MAAM;AAAA,MACtB,CAAC,SAAS,QAAQ,QAAQ;AAAA,MAC1B,CAAC,SAAS,QAAQ,QAAQ;AAAA,IAC5B,EAGA;AAAA,MACA,CAAC,CAAC,SAAS,QAAQ,MACjB,WACE;AAAA,QAAC;AAAA;AAAA,UAEC,SAAS,UAAM,sBAAW,EAAE,cAAc,QAAQ;AAAA,UAClD,aACE,aAAa,SACX,4CAAC,gCAAS,MAAK,QAAO,IAEtB;AAAA,YAAC;AAAA;AAAA,cACC,KAAK,UAAU,SAAS,YAAY,CAAC;AAAA,cACrC,KAAK;AAAA,cACL,OAAO;AAAA,gBACL,OAAO;AAAA,gBACP,QAAQ;AAAA,gBACR,QAAQ,UAAU,SAAS,cAAc;AAAA,cAC3C;AAAA;AAAA,UACF;AAAA,UAGJ,GAAG;AAAA,UACH,UAAU;AAAA,UAET;AAAA;AAAA,QApBI;AAAA,MAqBP;AAAA,IAEN,GACF;AAAA,KACF;AAEJ;","names":["import__"]}
@@ -0,0 +1,8 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { LoginBrandingProps } from './index.cjs';
3
+
4
+ declare function LoginHeader({ secondFactorPending, appName, iconLink, iconLinkAlt, }: {
5
+ secondFactorPending: boolean;
6
+ } & LoginBrandingProps): react_jsx_runtime.JSX.Element;
7
+
8
+ export { LoginHeader as default };
@@ -0,0 +1,8 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { LoginBrandingProps } from './index.js';
3
+
4
+ declare function LoginHeader({ secondFactorPending, appName, iconLink, iconLinkAlt, }: {
5
+ secondFactorPending: boolean;
6
+ } & LoginBrandingProps): react_jsx_runtime.JSX.Element;
7
+
8
+ export { LoginHeader as default };
@@ -0,0 +1,60 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import {
3
+ Button,
4
+ Group,
5
+ Stack,
6
+ Text,
7
+ useComputedColorScheme
8
+ } from "@mantine/core";
9
+ import { KeyRound } from "lucide-react";
10
+ import { authClient, useLoginOptions } from "../..";
11
+ function LoginHeader({
12
+ secondFactorPending,
13
+ appName,
14
+ iconLink,
15
+ iconLinkAlt
16
+ }) {
17
+ const options = useLoginOptions().data;
18
+ const theme = useComputedColorScheme();
19
+ return /* @__PURE__ */ jsxs(Group, { justify: "space-between", children: [
20
+ /* @__PURE__ */ jsxs(Group, { gap: "sm", children: [
21
+ /* @__PURE__ */ jsx("img", { src: iconLink, width: 42, height: 42, alt: iconLinkAlt }),
22
+ /* @__PURE__ */ jsxs(Stack, { gap: "0", children: [
23
+ /* @__PURE__ */ jsx(Text, { fz: "h2", fw: "450", lts: "0.1rem", children: appName }),
24
+ /* @__PURE__ */ jsx(Text, { size: "md", opacity: 0.6, mt: -8, children: "Log In" })
25
+ ] })
26
+ ] }),
27
+ /* @__PURE__ */ jsx(Group, { gap: "sm", children: [
28
+ [options?.oidc, "Oidc"],
29
+ [options?.github, "Github"],
30
+ [options?.google, "Google"]
31
+ ].map(
32
+ ([enabled, provider]) => enabled && /* @__PURE__ */ jsx(
33
+ Button,
34
+ {
35
+ onClick: () => authClient().externalLogin(provider),
36
+ leftSection: provider === "Oidc" ? /* @__PURE__ */ jsx(KeyRound, { size: "1rem" }) : /* @__PURE__ */ jsx(
37
+ "img",
38
+ {
39
+ src: `/icons/${provider.toLowerCase()}.svg`,
40
+ alt: provider,
41
+ style: {
42
+ width: "1rem",
43
+ height: "1rem",
44
+ filter: theme === "dark" ? "invert(1)" : void 0
45
+ }
46
+ }
47
+ ),
48
+ w: 110,
49
+ disabled: secondFactorPending,
50
+ children: provider
51
+ },
52
+ provider
53
+ )
54
+ ) })
55
+ ] });
56
+ }
57
+ export {
58
+ LoginHeader as default
59
+ };
60
+ //# sourceMappingURL=header.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/auth/login/header.tsx"],"sourcesContent":["import {\n Button,\n Group,\n Stack,\n Text,\n useComputedColorScheme,\n} from \"@mantine/core\";\nimport { KeyRound } from \"lucide-react\";\nimport * as MoghAuth from \"mogh_auth_client\";\nimport { LoginBrandingProps } from \".\";\nimport { authClient, useLoginOptions } from \"../..\";\n\nexport default function LoginHeader({\n secondFactorPending,\n appName,\n iconLink,\n iconLinkAlt,\n}: {\n secondFactorPending: boolean;\n} & LoginBrandingProps) {\n const options = useLoginOptions().data;\n const theme = useComputedColorScheme();\n return (\n <Group justify=\"space-between\">\n <Group gap=\"sm\">\n <img src={iconLink} width={42} height={42} alt={iconLinkAlt} />\n <Stack gap=\"0\">\n <Text fz=\"h2\" fw=\"450\" lts=\"0.1rem\">\n {appName}\n </Text>\n <Text size=\"md\" opacity={0.6} mt={-8}>\n Log In\n </Text>\n </Stack>\n </Group>\n <Group gap=\"sm\">\n {(\n [\n [options?.oidc, \"Oidc\"],\n [options?.github, \"Github\"],\n [options?.google, \"Google\"],\n ] as Array<\n [boolean | undefined, MoghAuth.Types.ExternalLoginProvider]\n >\n ).map(\n ([enabled, provider]) =>\n enabled && (\n <Button\n key={provider}\n onClick={() => authClient().externalLogin(provider)}\n leftSection={\n provider === \"Oidc\" ? (\n <KeyRound size=\"1rem\" />\n ) : (\n <img\n src={`/icons/${provider.toLowerCase()}.svg`}\n alt={provider}\n style={{\n width: \"1rem\",\n height: \"1rem\",\n filter: theme === \"dark\" ? \"invert(1)\" : undefined,\n }}\n />\n )\n }\n w={110}\n disabled={secondFactorPending}\n >\n {provider}\n </Button>\n ),\n )}\n </Group>\n </Group>\n );\n}\n"],"mappings":"AAyBQ,cACA,YADA;AAzBR;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,gBAAgB;AAGzB,SAAS,YAAY,uBAAuB;AAE7B,SAAR,YAA6B;AAAA,EAClC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAEwB;AACtB,QAAM,UAAU,gBAAgB,EAAE;AAClC,QAAM,QAAQ,uBAAuB;AACrC,SACE,qBAAC,SAAM,SAAQ,iBACb;AAAA,yBAAC,SAAM,KAAI,MACT;AAAA,0BAAC,SAAI,KAAK,UAAU,OAAO,IAAI,QAAQ,IAAI,KAAK,aAAa;AAAA,MAC7D,qBAAC,SAAM,KAAI,KACT;AAAA,4BAAC,QAAK,IAAG,MAAK,IAAG,OAAM,KAAI,UACxB,mBACH;AAAA,QACA,oBAAC,QAAK,MAAK,MAAK,SAAS,KAAK,IAAI,IAAI,oBAEtC;AAAA,SACF;AAAA,OACF;AAAA,IACA,oBAAC,SAAM,KAAI,MAEP;AAAA,MACE,CAAC,SAAS,MAAM,MAAM;AAAA,MACtB,CAAC,SAAS,QAAQ,QAAQ;AAAA,MAC1B,CAAC,SAAS,QAAQ,QAAQ;AAAA,IAC5B,EAGA;AAAA,MACA,CAAC,CAAC,SAAS,QAAQ,MACjB,WACE;AAAA,QAAC;AAAA;AAAA,UAEC,SAAS,MAAM,WAAW,EAAE,cAAc,QAAQ;AAAA,UAClD,aACE,aAAa,SACX,oBAAC,YAAS,MAAK,QAAO,IAEtB;AAAA,YAAC;AAAA;AAAA,cACC,KAAK,UAAU,SAAS,YAAY,CAAC;AAAA,cACrC,KAAK;AAAA,cACL,OAAO;AAA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