@githat/nextjs 0.2.5 → 0.2.7
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/index.d.mts +177 -1
- package/dist/index.d.ts +177 -1
- package/dist/index.js +581 -53
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +524 -1
- package/dist/index.mjs.map +1 -1
- package/dist/server.d.mts +41 -1
- package/dist/server.d.ts +41 -1
- package/dist/server.js +18 -0
- package/dist/server.js.map +1 -1
- package/dist/server.mjs +17 -0
- package/dist/server.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -432,6 +432,73 @@ function useGitHat() {
|
|
|
432
432
|
},
|
|
433
433
|
[client]
|
|
434
434
|
);
|
|
435
|
+
const getGitHubOAuthUrl = useCallback2(
|
|
436
|
+
async (options) => {
|
|
437
|
+
const params = new URLSearchParams();
|
|
438
|
+
if (options?.redirectUri) params.append("redirectUri", options.redirectUri);
|
|
439
|
+
if (options?.state) params.append("state", options.state);
|
|
440
|
+
const queryString = params.toString();
|
|
441
|
+
const path = queryString ? `/auth/oauth/github/url?${queryString}` : "/auth/oauth/github/url";
|
|
442
|
+
return client.fetchApi(path);
|
|
443
|
+
},
|
|
444
|
+
[client]
|
|
445
|
+
);
|
|
446
|
+
const signInWithGitHub = useCallback2(
|
|
447
|
+
async (code, options) => {
|
|
448
|
+
const response = await client.fetchApi("/auth/oauth/github", {
|
|
449
|
+
method: "POST",
|
|
450
|
+
body: JSON.stringify({
|
|
451
|
+
code,
|
|
452
|
+
redirectUri: options?.redirectUri
|
|
453
|
+
})
|
|
454
|
+
});
|
|
455
|
+
if (response.accessToken) {
|
|
456
|
+
window.dispatchEvent(new CustomEvent("githat:auth-changed", {
|
|
457
|
+
detail: { user: response.user, org: response.org, signedIn: true }
|
|
458
|
+
}));
|
|
459
|
+
}
|
|
460
|
+
return {
|
|
461
|
+
user: response.user,
|
|
462
|
+
org: response.org,
|
|
463
|
+
isNewUser: response.isNewUser
|
|
464
|
+
};
|
|
465
|
+
},
|
|
466
|
+
[client]
|
|
467
|
+
);
|
|
468
|
+
const getCognitoOAuthUrl = useCallback2(
|
|
469
|
+
async (options) => {
|
|
470
|
+
const params = new URLSearchParams();
|
|
471
|
+
if (options?.redirectUri) params.append("redirectUri", options.redirectUri);
|
|
472
|
+
if (options?.state) params.append("state", options.state);
|
|
473
|
+
if (options?.identityProvider) params.append("identityProvider", options.identityProvider);
|
|
474
|
+
const queryString = params.toString();
|
|
475
|
+
const path = queryString ? `/auth/oauth/cognito/url?${queryString}` : "/auth/oauth/cognito/url";
|
|
476
|
+
return client.fetchApi(path);
|
|
477
|
+
},
|
|
478
|
+
[client]
|
|
479
|
+
);
|
|
480
|
+
const signInWithCognito = useCallback2(
|
|
481
|
+
async (code, options) => {
|
|
482
|
+
const response = await client.fetchApi("/auth/oauth/cognito", {
|
|
483
|
+
method: "POST",
|
|
484
|
+
body: JSON.stringify({
|
|
485
|
+
code,
|
|
486
|
+
redirectUri: options?.redirectUri
|
|
487
|
+
})
|
|
488
|
+
});
|
|
489
|
+
if (response.accessToken) {
|
|
490
|
+
window.dispatchEvent(new CustomEvent("githat:auth-changed", {
|
|
491
|
+
detail: { user: response.user, org: response.org, signedIn: true }
|
|
492
|
+
}));
|
|
493
|
+
}
|
|
494
|
+
return {
|
|
495
|
+
user: response.user,
|
|
496
|
+
org: response.org,
|
|
497
|
+
isNewUser: response.isNewUser
|
|
498
|
+
};
|
|
499
|
+
},
|
|
500
|
+
[client]
|
|
501
|
+
);
|
|
435
502
|
return {
|
|
436
503
|
fetch: client.fetchApi,
|
|
437
504
|
getUserOrgs: () => client.fetchApi("/user/orgs"),
|
|
@@ -445,7 +512,12 @@ function useGitHat() {
|
|
|
445
512
|
changePassword,
|
|
446
513
|
// Email verification
|
|
447
514
|
verifyEmail,
|
|
448
|
-
resendVerificationEmail
|
|
515
|
+
resendVerificationEmail,
|
|
516
|
+
// OAuth (Web2)
|
|
517
|
+
getGitHubOAuthUrl,
|
|
518
|
+
signInWithGitHub,
|
|
519
|
+
getCognitoOAuthUrl,
|
|
520
|
+
signInWithCognito
|
|
449
521
|
};
|
|
450
522
|
}
|
|
451
523
|
|
|
@@ -527,6 +599,31 @@ function useData() {
|
|
|
527
599
|
}), [client]);
|
|
528
600
|
}
|
|
529
601
|
|
|
602
|
+
// src/email.ts
|
|
603
|
+
import { useMemo as useMemo4 } from "react";
|
|
604
|
+
function useEmail() {
|
|
605
|
+
const ctx = useAuth();
|
|
606
|
+
const client = useMemo4(
|
|
607
|
+
() => createClient(ctx.config.apiUrl, ctx.config.publishableKey),
|
|
608
|
+
[ctx.config.apiUrl, ctx.config.publishableKey]
|
|
609
|
+
);
|
|
610
|
+
return useMemo4(() => ({
|
|
611
|
+
/**
|
|
612
|
+
* Send a transactional email.
|
|
613
|
+
* @param options - Email options (to, subject, html/text, replyTo)
|
|
614
|
+
*/
|
|
615
|
+
send: async (options) => {
|
|
616
|
+
if (!options.to) throw new Error('Recipient "to" is required');
|
|
617
|
+
if (!options.subject) throw new Error("Subject is required");
|
|
618
|
+
if (!options.html && !options.text) throw new Error('At least one of "html" or "text" is required');
|
|
619
|
+
return client.fetchApi("/email/send", {
|
|
620
|
+
method: "POST",
|
|
621
|
+
body: JSON.stringify(options)
|
|
622
|
+
});
|
|
623
|
+
}
|
|
624
|
+
}), [client]);
|
|
625
|
+
}
|
|
626
|
+
|
|
530
627
|
// src/components/SignInForm.tsx
|
|
531
628
|
import { useState as useState2 } from "react";
|
|
532
629
|
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
@@ -1277,10 +1374,435 @@ function ChangePasswordForm({
|
|
|
1277
1374
|
] })
|
|
1278
1375
|
] });
|
|
1279
1376
|
}
|
|
1377
|
+
|
|
1378
|
+
// src/components/GitHubButton.tsx
|
|
1379
|
+
import { useState as useState11, useCallback as useCallback3 } from "react";
|
|
1380
|
+
import { jsx as jsx13, jsxs as jsxs11 } from "react/jsx-runtime";
|
|
1381
|
+
var GitHubIcon = () => /* @__PURE__ */ jsx13("svg", { width: "20", height: "20", viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ jsx13("path", { d: "M12 0C5.374 0 0 5.373 0 12c0 5.302 3.438 9.8 8.207 11.387.599.111.793-.261.793-.577v-2.234c-3.338.726-4.033-1.416-4.033-1.416-.546-1.387-1.333-1.756-1.333-1.756-1.089-.745.083-.729.083-.729 1.205.084 1.839 1.237 1.839 1.237 1.07 1.834 2.807 1.304 3.492.997.107-.775.418-1.305.762-1.604-2.665-.305-5.467-1.334-5.467-5.931 0-1.311.469-2.381 1.236-3.221-.124-.303-.535-1.524.117-3.176 0 0 1.008-.322 3.301 1.23A11.509 11.509 0 0112 5.803c1.02.005 2.047.138 3.006.404 2.291-1.552 3.297-1.23 3.297-1.23.653 1.653.242 2.874.118 3.176.77.84 1.235 1.911 1.235 3.221 0 4.609-2.807 5.624-5.479 5.921.43.372.823 1.102.823 2.222v3.293c0 .319.192.694.801.576C20.566 21.797 24 17.3 24 12c0-6.627-5.373-12-12-12z" }) });
|
|
1382
|
+
function GitHubButton({
|
|
1383
|
+
children = "Continue with GitHub",
|
|
1384
|
+
redirectUri,
|
|
1385
|
+
onSuccess,
|
|
1386
|
+
onError,
|
|
1387
|
+
className = "",
|
|
1388
|
+
variant = "default",
|
|
1389
|
+
disabled = false
|
|
1390
|
+
}) {
|
|
1391
|
+
const { getGitHubOAuthUrl } = useGitHat();
|
|
1392
|
+
const [isLoading, setIsLoading] = useState11(false);
|
|
1393
|
+
const handleClick = useCallback3(async () => {
|
|
1394
|
+
if (isLoading || disabled) return;
|
|
1395
|
+
setIsLoading(true);
|
|
1396
|
+
try {
|
|
1397
|
+
const state = crypto.randomUUID();
|
|
1398
|
+
sessionStorage.setItem("githat_oauth_state", state);
|
|
1399
|
+
const { url } = await getGitHubOAuthUrl({ redirectUri, state });
|
|
1400
|
+
window.location.href = url;
|
|
1401
|
+
} catch (error) {
|
|
1402
|
+
setIsLoading(false);
|
|
1403
|
+
if (onError) {
|
|
1404
|
+
onError(error instanceof Error ? error : new Error("Failed to start GitHub OAuth"));
|
|
1405
|
+
}
|
|
1406
|
+
}
|
|
1407
|
+
}, [getGitHubOAuthUrl, redirectUri, onError, isLoading, disabled]);
|
|
1408
|
+
const baseStyles = "githat-github-button";
|
|
1409
|
+
const variantStyles = variant === "outline" ? "githat-github-button-outline" : "";
|
|
1410
|
+
const disabledStyles = disabled || isLoading ? "githat-github-button-disabled" : "";
|
|
1411
|
+
return /* @__PURE__ */ jsxs11(
|
|
1412
|
+
"button",
|
|
1413
|
+
{
|
|
1414
|
+
type: "button",
|
|
1415
|
+
onClick: handleClick,
|
|
1416
|
+
disabled: disabled || isLoading,
|
|
1417
|
+
className: `${baseStyles} ${variantStyles} ${disabledStyles} ${className}`.trim(),
|
|
1418
|
+
children: [
|
|
1419
|
+
isLoading ? /* @__PURE__ */ jsx13("span", { className: "githat-github-spinner" }) : /* @__PURE__ */ jsx13(GitHubIcon, {}),
|
|
1420
|
+
/* @__PURE__ */ jsx13("span", { children })
|
|
1421
|
+
]
|
|
1422
|
+
}
|
|
1423
|
+
);
|
|
1424
|
+
}
|
|
1425
|
+
if (typeof document !== "undefined") {
|
|
1426
|
+
const styleId = "githat-github-button-styles";
|
|
1427
|
+
if (!document.getElementById(styleId)) {
|
|
1428
|
+
const style = document.createElement("style");
|
|
1429
|
+
style.id = styleId;
|
|
1430
|
+
style.textContent = `
|
|
1431
|
+
.githat-github-button {
|
|
1432
|
+
display: inline-flex;
|
|
1433
|
+
align-items: center;
|
|
1434
|
+
justify-content: center;
|
|
1435
|
+
gap: 0.5rem;
|
|
1436
|
+
padding: 0.625rem 1rem;
|
|
1437
|
+
font-size: 0.875rem;
|
|
1438
|
+
font-weight: 500;
|
|
1439
|
+
border-radius: 0.375rem;
|
|
1440
|
+
border: none;
|
|
1441
|
+
cursor: pointer;
|
|
1442
|
+
transition: all 0.15s ease;
|
|
1443
|
+
background-color: #24292f;
|
|
1444
|
+
color: #ffffff;
|
|
1445
|
+
width: 100%;
|
|
1446
|
+
}
|
|
1447
|
+
.githat-github-button:hover:not(:disabled) {
|
|
1448
|
+
background-color: #32383f;
|
|
1449
|
+
}
|
|
1450
|
+
.githat-github-button-outline {
|
|
1451
|
+
background-color: transparent;
|
|
1452
|
+
color: #24292f;
|
|
1453
|
+
border: 1px solid #d0d7de;
|
|
1454
|
+
}
|
|
1455
|
+
.githat-github-button-outline:hover:not(:disabled) {
|
|
1456
|
+
background-color: #f6f8fa;
|
|
1457
|
+
border-color: #24292f;
|
|
1458
|
+
}
|
|
1459
|
+
.githat-github-button-disabled {
|
|
1460
|
+
opacity: 0.5;
|
|
1461
|
+
cursor: not-allowed;
|
|
1462
|
+
}
|
|
1463
|
+
.githat-github-spinner {
|
|
1464
|
+
width: 1rem;
|
|
1465
|
+
height: 1rem;
|
|
1466
|
+
border: 2px solid currentColor;
|
|
1467
|
+
border-top-color: transparent;
|
|
1468
|
+
border-radius: 50%;
|
|
1469
|
+
animation: githat-spin 0.6s linear infinite;
|
|
1470
|
+
}
|
|
1471
|
+
@keyframes githat-spin {
|
|
1472
|
+
to { transform: rotate(360deg); }
|
|
1473
|
+
}
|
|
1474
|
+
`;
|
|
1475
|
+
document.head.appendChild(style);
|
|
1476
|
+
}
|
|
1477
|
+
}
|
|
1478
|
+
|
|
1479
|
+
// src/components/GitHubCallback.tsx
|
|
1480
|
+
import { useEffect as useEffect6, useState as useState12 } from "react";
|
|
1481
|
+
import { Fragment as Fragment3, jsx as jsx14, jsxs as jsxs12 } from "react/jsx-runtime";
|
|
1482
|
+
function GitHubCallback({
|
|
1483
|
+
redirectUrl = "/dashboard",
|
|
1484
|
+
newUserRedirectUrl,
|
|
1485
|
+
onSuccess,
|
|
1486
|
+
onError,
|
|
1487
|
+
loadingComponent,
|
|
1488
|
+
errorComponent
|
|
1489
|
+
}) {
|
|
1490
|
+
const { signInWithGitHub } = useGitHat();
|
|
1491
|
+
const { config } = useAuth();
|
|
1492
|
+
const [error, setError] = useState12(null);
|
|
1493
|
+
const [isProcessing, setIsProcessing] = useState12(true);
|
|
1494
|
+
useEffect6(() => {
|
|
1495
|
+
const handleCallback = async () => {
|
|
1496
|
+
const params = new URLSearchParams(window.location.search);
|
|
1497
|
+
const code = params.get("code");
|
|
1498
|
+
const state = params.get("state");
|
|
1499
|
+
const errorParam = params.get("error");
|
|
1500
|
+
const errorDescription = params.get("error_description");
|
|
1501
|
+
if (errorParam) {
|
|
1502
|
+
const errorMsg = errorDescription || errorParam;
|
|
1503
|
+
setError(errorMsg);
|
|
1504
|
+
setIsProcessing(false);
|
|
1505
|
+
if (onError) {
|
|
1506
|
+
onError(new Error(errorMsg));
|
|
1507
|
+
}
|
|
1508
|
+
return;
|
|
1509
|
+
}
|
|
1510
|
+
if (!code) {
|
|
1511
|
+
const errorMsg = "No authorization code received";
|
|
1512
|
+
setError(errorMsg);
|
|
1513
|
+
setIsProcessing(false);
|
|
1514
|
+
if (onError) {
|
|
1515
|
+
onError(new Error(errorMsg));
|
|
1516
|
+
}
|
|
1517
|
+
return;
|
|
1518
|
+
}
|
|
1519
|
+
const savedState = sessionStorage.getItem("githat_oauth_state");
|
|
1520
|
+
if (savedState && state !== savedState) {
|
|
1521
|
+
const errorMsg = "Invalid state parameter";
|
|
1522
|
+
setError(errorMsg);
|
|
1523
|
+
setIsProcessing(false);
|
|
1524
|
+
if (onError) {
|
|
1525
|
+
onError(new Error(errorMsg));
|
|
1526
|
+
}
|
|
1527
|
+
return;
|
|
1528
|
+
}
|
|
1529
|
+
sessionStorage.removeItem("githat_oauth_state");
|
|
1530
|
+
try {
|
|
1531
|
+
const result = await signInWithGitHub(code);
|
|
1532
|
+
if (onSuccess) {
|
|
1533
|
+
onSuccess(result);
|
|
1534
|
+
}
|
|
1535
|
+
const targetUrl = result.isNewUser && newUserRedirectUrl ? newUserRedirectUrl : redirectUrl || config.afterSignInUrl || "/dashboard";
|
|
1536
|
+
window.location.href = targetUrl;
|
|
1537
|
+
} catch (err) {
|
|
1538
|
+
const errorMsg = err instanceof Error ? err.message : "Authentication failed";
|
|
1539
|
+
setError(errorMsg);
|
|
1540
|
+
setIsProcessing(false);
|
|
1541
|
+
if (onError) {
|
|
1542
|
+
onError(err instanceof Error ? err : new Error(errorMsg));
|
|
1543
|
+
}
|
|
1544
|
+
}
|
|
1545
|
+
};
|
|
1546
|
+
handleCallback();
|
|
1547
|
+
}, [signInWithGitHub, redirectUrl, newUserRedirectUrl, config.afterSignInUrl, onSuccess, onError]);
|
|
1548
|
+
if (error) {
|
|
1549
|
+
if (errorComponent) {
|
|
1550
|
+
return /* @__PURE__ */ jsx14(Fragment3, { children: errorComponent(error) });
|
|
1551
|
+
}
|
|
1552
|
+
return /* @__PURE__ */ jsxs12("div", { className: "githat-callback-error", children: [
|
|
1553
|
+
/* @__PURE__ */ jsx14("h2", { children: "Authentication Failed" }),
|
|
1554
|
+
/* @__PURE__ */ jsx14("p", { children: error }),
|
|
1555
|
+
/* @__PURE__ */ jsx14("a", { href: "/sign-in", children: "Back to Sign In" })
|
|
1556
|
+
] });
|
|
1557
|
+
}
|
|
1558
|
+
if (loadingComponent) {
|
|
1559
|
+
return /* @__PURE__ */ jsx14(Fragment3, { children: loadingComponent });
|
|
1560
|
+
}
|
|
1561
|
+
return /* @__PURE__ */ jsxs12("div", { className: "githat-callback-loading", children: [
|
|
1562
|
+
/* @__PURE__ */ jsx14("div", { className: "githat-callback-spinner" }),
|
|
1563
|
+
/* @__PURE__ */ jsx14("p", { children: "Completing sign in with GitHub..." })
|
|
1564
|
+
] });
|
|
1565
|
+
}
|
|
1566
|
+
if (typeof document !== "undefined") {
|
|
1567
|
+
const styleId = "githat-callback-styles";
|
|
1568
|
+
if (!document.getElementById(styleId)) {
|
|
1569
|
+
const style = document.createElement("style");
|
|
1570
|
+
style.id = styleId;
|
|
1571
|
+
style.textContent = `
|
|
1572
|
+
.githat-callback-loading,
|
|
1573
|
+
.githat-callback-error {
|
|
1574
|
+
display: flex;
|
|
1575
|
+
flex-direction: column;
|
|
1576
|
+
align-items: center;
|
|
1577
|
+
justify-content: center;
|
|
1578
|
+
min-height: 200px;
|
|
1579
|
+
padding: 2rem;
|
|
1580
|
+
text-align: center;
|
|
1581
|
+
}
|
|
1582
|
+
.githat-callback-spinner {
|
|
1583
|
+
width: 2rem;
|
|
1584
|
+
height: 2rem;
|
|
1585
|
+
border: 3px solid #e5e7eb;
|
|
1586
|
+
border-top-color: #3b82f6;
|
|
1587
|
+
border-radius: 50%;
|
|
1588
|
+
animation: githat-spin 0.8s linear infinite;
|
|
1589
|
+
margin-bottom: 1rem;
|
|
1590
|
+
}
|
|
1591
|
+
.githat-callback-error h2 {
|
|
1592
|
+
color: #dc2626;
|
|
1593
|
+
margin-bottom: 0.5rem;
|
|
1594
|
+
}
|
|
1595
|
+
.githat-callback-error p {
|
|
1596
|
+
color: #6b7280;
|
|
1597
|
+
margin-bottom: 1rem;
|
|
1598
|
+
}
|
|
1599
|
+
.githat-callback-error a {
|
|
1600
|
+
color: #3b82f6;
|
|
1601
|
+
text-decoration: underline;
|
|
1602
|
+
}
|
|
1603
|
+
@keyframes githat-spin {
|
|
1604
|
+
to { transform: rotate(360deg); }
|
|
1605
|
+
}
|
|
1606
|
+
`;
|
|
1607
|
+
document.head.appendChild(style);
|
|
1608
|
+
}
|
|
1609
|
+
}
|
|
1610
|
+
|
|
1611
|
+
// src/components/CognitoButton.tsx
|
|
1612
|
+
import { useState as useState13, useCallback as useCallback4 } from "react";
|
|
1613
|
+
import { jsx as jsx15, jsxs as jsxs13 } from "react/jsx-runtime";
|
|
1614
|
+
var AWSIcon = () => /* @__PURE__ */ jsx15("svg", { width: "20", height: "20", viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ jsx15("path", { d: "M6.763 10.036c0 .296.032.535.088.71.064.176.144.368.256.576.04.063.056.127.056.183 0 .08-.048.16-.152.24l-.503.335a.383.383 0 0 1-.208.072c-.08 0-.16-.04-.239-.112a2.47 2.47 0 0 1-.287-.375 6.18 6.18 0 0 1-.248-.471c-.622.734-1.405 1.101-2.347 1.101-.67 0-1.205-.191-1.596-.574-.391-.384-.59-.894-.59-1.533 0-.678.239-1.23.726-1.644.487-.415 1.133-.623 1.955-.623.272 0 .551.024.846.064.296.04.6.104.918.176v-.583c0-.607-.127-1.03-.375-1.277-.255-.248-.686-.367-1.3-.367-.28 0-.568.031-.863.103-.295.072-.583.16-.862.272a2.287 2.287 0 0 1-.28.104.488.488 0 0 1-.127.023c-.112 0-.168-.08-.168-.247v-.391c0-.128.016-.224.056-.28a.597.597 0 0 1 .224-.167c.279-.144.614-.264 1.005-.36a4.84 4.84 0 0 1 1.246-.151c.95 0 1.644.216 2.091.647.439.43.662 1.085.662 1.963v2.586zm-3.24 1.214c.263 0 .534-.048.822-.144.287-.096.543-.271.758-.51.128-.152.224-.32.272-.512.047-.191.08-.423.08-.694v-.335a6.66 6.66 0 0 0-.735-.136 6.02 6.02 0 0 0-.75-.048c-.535 0-.926.104-1.19.32-.263.215-.39.518-.39.917 0 .375.095.655.295.846.191.2.47.296.838.296zm6.41.862c-.144 0-.24-.024-.304-.08-.064-.048-.12-.16-.168-.311L7.586 5.55a1.398 1.398 0 0 1-.072-.32c0-.128.064-.2.191-.2h.783c.151 0 .255.025.31.08.065.048.113.16.16.312l1.342 5.284 1.245-5.284c.04-.16.088-.264.151-.312a.549.549 0 0 1 .32-.08h.638c.152 0 .256.025.32.08.063.048.12.16.151.312l1.261 5.348 1.381-5.348c.048-.16.104-.264.16-.312a.52.52 0 0 1 .311-.08h.743c.127 0 .2.065.2.2 0 .04-.009.08-.017.128a1.137 1.137 0 0 1-.056.2l-1.923 6.17c-.048.16-.104.264-.168.312a.51.51 0 0 1-.303.08h-.687c-.151 0-.255-.024-.32-.08-.063-.056-.119-.16-.15-.32l-1.238-5.148-1.23 5.14c-.04.16-.087.264-.15.32-.065.056-.177.08-.32.08zm10.256.215c-.415 0-.83-.048-1.229-.143-.399-.096-.71-.2-.918-.32-.128-.071-.215-.151-.247-.223a.563.563 0 0 1-.048-.224v-.407c0-.167.064-.247.183-.247.048 0 .096.008.144.024.048.016.12.048.2.08.271.12.566.215.878.279.319.064.63.096.95.096.502 0 .894-.088 1.165-.264a.86.86 0 0 0 .415-.758.777.777 0 0 0-.215-.559c-.144-.151-.415-.287-.806-.415l-1.157-.36c-.583-.183-1.014-.454-1.277-.813a1.902 1.902 0 0 1-.4-1.158c0-.335.073-.63.216-.886.144-.255.336-.479.575-.654.24-.184.51-.32.83-.415.32-.096.655-.136 1.006-.136.176 0 .359.008.535.032.183.024.35.056.518.088.16.04.312.08.455.127.144.048.256.096.336.144a.69.69 0 0 1 .24.2.43.43 0 0 1 .071.263v.375c0 .168-.064.256-.184.256a.83.83 0 0 1-.303-.096 3.652 3.652 0 0 0-1.532-.311c-.455 0-.815.071-1.062.223-.248.152-.375.383-.375.71 0 .224.08.416.24.567.159.152.454.304.877.44l1.134.358c.574.184.99.44 1.237.767.247.327.367.702.367 1.117 0 .343-.072.655-.207.926-.144.272-.336.511-.583.703-.248.2-.543.343-.886.447-.36.111-.734.167-1.142.167z" }) });
|
|
1615
|
+
function CognitoButton({
|
|
1616
|
+
children = "Continue with AWS",
|
|
1617
|
+
redirectUri,
|
|
1618
|
+
identityProvider,
|
|
1619
|
+
onError,
|
|
1620
|
+
className = "",
|
|
1621
|
+
variant = "default",
|
|
1622
|
+
disabled = false
|
|
1623
|
+
}) {
|
|
1624
|
+
const { getCognitoOAuthUrl } = useGitHat();
|
|
1625
|
+
const [isLoading, setIsLoading] = useState13(false);
|
|
1626
|
+
const handleClick = useCallback4(async () => {
|
|
1627
|
+
if (isLoading || disabled) return;
|
|
1628
|
+
setIsLoading(true);
|
|
1629
|
+
try {
|
|
1630
|
+
const state = crypto.randomUUID();
|
|
1631
|
+
sessionStorage.setItem("githat_cognito_oauth_state", state);
|
|
1632
|
+
const { url } = await getCognitoOAuthUrl({ redirectUri, state, identityProvider });
|
|
1633
|
+
window.location.href = url;
|
|
1634
|
+
} catch (error) {
|
|
1635
|
+
setIsLoading(false);
|
|
1636
|
+
if (onError) {
|
|
1637
|
+
onError(error instanceof Error ? error : new Error("Failed to start Cognito OAuth"));
|
|
1638
|
+
}
|
|
1639
|
+
}
|
|
1640
|
+
}, [getCognitoOAuthUrl, redirectUri, identityProvider, onError, isLoading, disabled]);
|
|
1641
|
+
const baseStyles = "githat-cognito-button";
|
|
1642
|
+
const variantStyles = variant === "outline" ? "githat-cognito-button-outline" : "";
|
|
1643
|
+
const disabledStyles = disabled || isLoading ? "githat-cognito-button-disabled" : "";
|
|
1644
|
+
return /* @__PURE__ */ jsxs13(
|
|
1645
|
+
"button",
|
|
1646
|
+
{
|
|
1647
|
+
type: "button",
|
|
1648
|
+
onClick: handleClick,
|
|
1649
|
+
disabled: disabled || isLoading,
|
|
1650
|
+
className: `${baseStyles} ${variantStyles} ${disabledStyles} ${className}`.trim(),
|
|
1651
|
+
children: [
|
|
1652
|
+
isLoading ? /* @__PURE__ */ jsx15("span", { className: "githat-cognito-spinner" }) : /* @__PURE__ */ jsx15(AWSIcon, {}),
|
|
1653
|
+
/* @__PURE__ */ jsx15("span", { children })
|
|
1654
|
+
]
|
|
1655
|
+
}
|
|
1656
|
+
);
|
|
1657
|
+
}
|
|
1658
|
+
if (typeof document !== "undefined") {
|
|
1659
|
+
const styleId = "githat-cognito-button-styles";
|
|
1660
|
+
if (!document.getElementById(styleId)) {
|
|
1661
|
+
const style = document.createElement("style");
|
|
1662
|
+
style.id = styleId;
|
|
1663
|
+
style.textContent = `
|
|
1664
|
+
.githat-cognito-button {
|
|
1665
|
+
display: inline-flex;
|
|
1666
|
+
align-items: center;
|
|
1667
|
+
justify-content: center;
|
|
1668
|
+
gap: 0.5rem;
|
|
1669
|
+
padding: 0.625rem 1rem;
|
|
1670
|
+
font-size: 0.875rem;
|
|
1671
|
+
font-weight: 500;
|
|
1672
|
+
border-radius: 0.375rem;
|
|
1673
|
+
border: none;
|
|
1674
|
+
cursor: pointer;
|
|
1675
|
+
transition: all 0.15s ease;
|
|
1676
|
+
background-color: #ff9900;
|
|
1677
|
+
color: #232f3e;
|
|
1678
|
+
width: 100%;
|
|
1679
|
+
}
|
|
1680
|
+
.githat-cognito-button:hover:not(:disabled) {
|
|
1681
|
+
background-color: #ec7211;
|
|
1682
|
+
}
|
|
1683
|
+
.githat-cognito-button-outline {
|
|
1684
|
+
background-color: transparent;
|
|
1685
|
+
color: #ff9900;
|
|
1686
|
+
border: 1px solid #ff9900;
|
|
1687
|
+
}
|
|
1688
|
+
.githat-cognito-button-outline:hover:not(:disabled) {
|
|
1689
|
+
background-color: rgba(255, 153, 0, 0.1);
|
|
1690
|
+
}
|
|
1691
|
+
.githat-cognito-button-disabled {
|
|
1692
|
+
opacity: 0.5;
|
|
1693
|
+
cursor: not-allowed;
|
|
1694
|
+
}
|
|
1695
|
+
.githat-cognito-spinner {
|
|
1696
|
+
width: 1rem;
|
|
1697
|
+
height: 1rem;
|
|
1698
|
+
border: 2px solid currentColor;
|
|
1699
|
+
border-top-color: transparent;
|
|
1700
|
+
border-radius: 50%;
|
|
1701
|
+
animation: githat-cognito-spin 0.6s linear infinite;
|
|
1702
|
+
}
|
|
1703
|
+
@keyframes githat-cognito-spin {
|
|
1704
|
+
to { transform: rotate(360deg); }
|
|
1705
|
+
}
|
|
1706
|
+
`;
|
|
1707
|
+
document.head.appendChild(style);
|
|
1708
|
+
}
|
|
1709
|
+
}
|
|
1710
|
+
|
|
1711
|
+
// src/components/CognitoCallback.tsx
|
|
1712
|
+
import { useEffect as useEffect7, useState as useState14 } from "react";
|
|
1713
|
+
import { Fragment as Fragment4, jsx as jsx16, jsxs as jsxs14 } from "react/jsx-runtime";
|
|
1714
|
+
function CognitoCallback({
|
|
1715
|
+
redirectUrl = "/dashboard",
|
|
1716
|
+
newUserRedirectUrl,
|
|
1717
|
+
onSuccess,
|
|
1718
|
+
onError,
|
|
1719
|
+
loadingComponent,
|
|
1720
|
+
errorComponent
|
|
1721
|
+
}) {
|
|
1722
|
+
const { signInWithCognito } = useGitHat();
|
|
1723
|
+
const { config } = useAuth();
|
|
1724
|
+
const [error, setError] = useState14(null);
|
|
1725
|
+
const [isProcessing, setIsProcessing] = useState14(true);
|
|
1726
|
+
useEffect7(() => {
|
|
1727
|
+
const handleCallback = async () => {
|
|
1728
|
+
const params = new URLSearchParams(window.location.search);
|
|
1729
|
+
const code = params.get("code");
|
|
1730
|
+
const state = params.get("state");
|
|
1731
|
+
const errorParam = params.get("error");
|
|
1732
|
+
const errorDescription = params.get("error_description");
|
|
1733
|
+
if (errorParam) {
|
|
1734
|
+
const errorMsg = errorDescription || errorParam;
|
|
1735
|
+
setError(errorMsg);
|
|
1736
|
+
setIsProcessing(false);
|
|
1737
|
+
if (onError) {
|
|
1738
|
+
onError(new Error(errorMsg));
|
|
1739
|
+
}
|
|
1740
|
+
return;
|
|
1741
|
+
}
|
|
1742
|
+
if (!code) {
|
|
1743
|
+
const errorMsg = "No authorization code received";
|
|
1744
|
+
setError(errorMsg);
|
|
1745
|
+
setIsProcessing(false);
|
|
1746
|
+
if (onError) {
|
|
1747
|
+
onError(new Error(errorMsg));
|
|
1748
|
+
}
|
|
1749
|
+
return;
|
|
1750
|
+
}
|
|
1751
|
+
const savedState = sessionStorage.getItem("githat_cognito_oauth_state");
|
|
1752
|
+
if (savedState && state !== savedState) {
|
|
1753
|
+
const errorMsg = "Invalid state parameter";
|
|
1754
|
+
setError(errorMsg);
|
|
1755
|
+
setIsProcessing(false);
|
|
1756
|
+
if (onError) {
|
|
1757
|
+
onError(new Error(errorMsg));
|
|
1758
|
+
}
|
|
1759
|
+
return;
|
|
1760
|
+
}
|
|
1761
|
+
sessionStorage.removeItem("githat_cognito_oauth_state");
|
|
1762
|
+
try {
|
|
1763
|
+
const result = await signInWithCognito(code);
|
|
1764
|
+
if (onSuccess) {
|
|
1765
|
+
onSuccess(result);
|
|
1766
|
+
}
|
|
1767
|
+
const targetUrl = result.isNewUser && newUserRedirectUrl ? newUserRedirectUrl : redirectUrl || config.afterSignInUrl || "/dashboard";
|
|
1768
|
+
window.location.href = targetUrl;
|
|
1769
|
+
} catch (err) {
|
|
1770
|
+
const errorMsg = err instanceof Error ? err.message : "Authentication failed";
|
|
1771
|
+
setError(errorMsg);
|
|
1772
|
+
setIsProcessing(false);
|
|
1773
|
+
if (onError) {
|
|
1774
|
+
onError(err instanceof Error ? err : new Error(errorMsg));
|
|
1775
|
+
}
|
|
1776
|
+
}
|
|
1777
|
+
};
|
|
1778
|
+
handleCallback();
|
|
1779
|
+
}, [signInWithCognito, redirectUrl, newUserRedirectUrl, config.afterSignInUrl, onSuccess, onError]);
|
|
1780
|
+
if (error) {
|
|
1781
|
+
if (errorComponent) {
|
|
1782
|
+
return /* @__PURE__ */ jsx16(Fragment4, { children: errorComponent(error) });
|
|
1783
|
+
}
|
|
1784
|
+
return /* @__PURE__ */ jsxs14("div", { className: "githat-callback-error", children: [
|
|
1785
|
+
/* @__PURE__ */ jsx16("h2", { children: "Authentication Failed" }),
|
|
1786
|
+
/* @__PURE__ */ jsx16("p", { children: error }),
|
|
1787
|
+
/* @__PURE__ */ jsx16("a", { href: "/sign-in", children: "Back to Sign In" })
|
|
1788
|
+
] });
|
|
1789
|
+
}
|
|
1790
|
+
if (loadingComponent) {
|
|
1791
|
+
return /* @__PURE__ */ jsx16(Fragment4, { children: loadingComponent });
|
|
1792
|
+
}
|
|
1793
|
+
return /* @__PURE__ */ jsxs14("div", { className: "githat-callback-loading", children: [
|
|
1794
|
+
/* @__PURE__ */ jsx16("div", { className: "githat-callback-spinner" }),
|
|
1795
|
+
/* @__PURE__ */ jsx16("p", { children: "Completing sign in with AWS Cognito..." })
|
|
1796
|
+
] });
|
|
1797
|
+
}
|
|
1280
1798
|
export {
|
|
1281
1799
|
ChangePasswordForm,
|
|
1800
|
+
CognitoButton,
|
|
1801
|
+
CognitoCallback,
|
|
1282
1802
|
ForgotPasswordForm,
|
|
1283
1803
|
GitHatProvider,
|
|
1804
|
+
GitHubButton,
|
|
1805
|
+
GitHubCallback,
|
|
1284
1806
|
OrgSwitcher,
|
|
1285
1807
|
ProtectedRoute,
|
|
1286
1808
|
ResetPasswordForm,
|
|
@@ -1293,6 +1815,7 @@ export {
|
|
|
1293
1815
|
VerifyEmailStatus,
|
|
1294
1816
|
useAuth,
|
|
1295
1817
|
useData,
|
|
1818
|
+
useEmail,
|
|
1296
1819
|
useGitHat
|
|
1297
1820
|
};
|
|
1298
1821
|
//# sourceMappingURL=index.mjs.map
|