@githat/nextjs 0.2.5 → 0.2.6
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 +113 -1
- package/dist/index.d.ts +113 -1
- package/dist/index.js +502 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +498 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -22,8 +22,12 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
22
22
|
var src_exports = {};
|
|
23
23
|
__export(src_exports, {
|
|
24
24
|
ChangePasswordForm: () => ChangePasswordForm,
|
|
25
|
+
CognitoButton: () => CognitoButton,
|
|
26
|
+
CognitoCallback: () => CognitoCallback,
|
|
25
27
|
ForgotPasswordForm: () => ForgotPasswordForm,
|
|
26
28
|
GitHatProvider: () => GitHatProvider,
|
|
29
|
+
GitHubButton: () => GitHubButton,
|
|
30
|
+
GitHubCallback: () => GitHubCallback,
|
|
27
31
|
OrgSwitcher: () => OrgSwitcher,
|
|
28
32
|
ProtectedRoute: () => ProtectedRoute,
|
|
29
33
|
ResetPasswordForm: () => ResetPasswordForm,
|
|
@@ -472,6 +476,73 @@ function useGitHat() {
|
|
|
472
476
|
},
|
|
473
477
|
[client]
|
|
474
478
|
);
|
|
479
|
+
const getGitHubOAuthUrl = (0, import_react2.useCallback)(
|
|
480
|
+
async (options) => {
|
|
481
|
+
const params = new URLSearchParams();
|
|
482
|
+
if (options?.redirectUri) params.append("redirectUri", options.redirectUri);
|
|
483
|
+
if (options?.state) params.append("state", options.state);
|
|
484
|
+
const queryString = params.toString();
|
|
485
|
+
const path = queryString ? `/auth/oauth/github/url?${queryString}` : "/auth/oauth/github/url";
|
|
486
|
+
return client.fetchApi(path);
|
|
487
|
+
},
|
|
488
|
+
[client]
|
|
489
|
+
);
|
|
490
|
+
const signInWithGitHub = (0, import_react2.useCallback)(
|
|
491
|
+
async (code, options) => {
|
|
492
|
+
const response = await client.fetchApi("/auth/oauth/github", {
|
|
493
|
+
method: "POST",
|
|
494
|
+
body: JSON.stringify({
|
|
495
|
+
code,
|
|
496
|
+
redirectUri: options?.redirectUri
|
|
497
|
+
})
|
|
498
|
+
});
|
|
499
|
+
if (response.accessToken) {
|
|
500
|
+
window.dispatchEvent(new CustomEvent("githat:auth-changed", {
|
|
501
|
+
detail: { user: response.user, org: response.org, signedIn: true }
|
|
502
|
+
}));
|
|
503
|
+
}
|
|
504
|
+
return {
|
|
505
|
+
user: response.user,
|
|
506
|
+
org: response.org,
|
|
507
|
+
isNewUser: response.isNewUser
|
|
508
|
+
};
|
|
509
|
+
},
|
|
510
|
+
[client]
|
|
511
|
+
);
|
|
512
|
+
const getCognitoOAuthUrl = (0, import_react2.useCallback)(
|
|
513
|
+
async (options) => {
|
|
514
|
+
const params = new URLSearchParams();
|
|
515
|
+
if (options?.redirectUri) params.append("redirectUri", options.redirectUri);
|
|
516
|
+
if (options?.state) params.append("state", options.state);
|
|
517
|
+
if (options?.identityProvider) params.append("identityProvider", options.identityProvider);
|
|
518
|
+
const queryString = params.toString();
|
|
519
|
+
const path = queryString ? `/auth/oauth/cognito/url?${queryString}` : "/auth/oauth/cognito/url";
|
|
520
|
+
return client.fetchApi(path);
|
|
521
|
+
},
|
|
522
|
+
[client]
|
|
523
|
+
);
|
|
524
|
+
const signInWithCognito = (0, import_react2.useCallback)(
|
|
525
|
+
async (code, options) => {
|
|
526
|
+
const response = await client.fetchApi("/auth/oauth/cognito", {
|
|
527
|
+
method: "POST",
|
|
528
|
+
body: JSON.stringify({
|
|
529
|
+
code,
|
|
530
|
+
redirectUri: options?.redirectUri
|
|
531
|
+
})
|
|
532
|
+
});
|
|
533
|
+
if (response.accessToken) {
|
|
534
|
+
window.dispatchEvent(new CustomEvent("githat:auth-changed", {
|
|
535
|
+
detail: { user: response.user, org: response.org, signedIn: true }
|
|
536
|
+
}));
|
|
537
|
+
}
|
|
538
|
+
return {
|
|
539
|
+
user: response.user,
|
|
540
|
+
org: response.org,
|
|
541
|
+
isNewUser: response.isNewUser
|
|
542
|
+
};
|
|
543
|
+
},
|
|
544
|
+
[client]
|
|
545
|
+
);
|
|
475
546
|
return {
|
|
476
547
|
fetch: client.fetchApi,
|
|
477
548
|
getUserOrgs: () => client.fetchApi("/user/orgs"),
|
|
@@ -485,7 +556,12 @@ function useGitHat() {
|
|
|
485
556
|
changePassword,
|
|
486
557
|
// Email verification
|
|
487
558
|
verifyEmail,
|
|
488
|
-
resendVerificationEmail
|
|
559
|
+
resendVerificationEmail,
|
|
560
|
+
// OAuth (Web2)
|
|
561
|
+
getGitHubOAuthUrl,
|
|
562
|
+
signInWithGitHub,
|
|
563
|
+
getCognitoOAuthUrl,
|
|
564
|
+
signInWithCognito
|
|
489
565
|
};
|
|
490
566
|
}
|
|
491
567
|
|
|
@@ -1317,11 +1393,436 @@ function ChangePasswordForm({
|
|
|
1317
1393
|
] })
|
|
1318
1394
|
] });
|
|
1319
1395
|
}
|
|
1396
|
+
|
|
1397
|
+
// src/components/GitHubButton.tsx
|
|
1398
|
+
var import_react15 = require("react");
|
|
1399
|
+
var import_jsx_runtime14 = require("react/jsx-runtime");
|
|
1400
|
+
var GitHubIcon = () => /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("svg", { width: "20", height: "20", viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("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" }) });
|
|
1401
|
+
function GitHubButton({
|
|
1402
|
+
children = "Continue with GitHub",
|
|
1403
|
+
redirectUri,
|
|
1404
|
+
onSuccess,
|
|
1405
|
+
onError,
|
|
1406
|
+
className = "",
|
|
1407
|
+
variant = "default",
|
|
1408
|
+
disabled = false
|
|
1409
|
+
}) {
|
|
1410
|
+
const { getGitHubOAuthUrl } = useGitHat();
|
|
1411
|
+
const [isLoading, setIsLoading] = (0, import_react15.useState)(false);
|
|
1412
|
+
const handleClick = (0, import_react15.useCallback)(async () => {
|
|
1413
|
+
if (isLoading || disabled) return;
|
|
1414
|
+
setIsLoading(true);
|
|
1415
|
+
try {
|
|
1416
|
+
const state = crypto.randomUUID();
|
|
1417
|
+
sessionStorage.setItem("githat_oauth_state", state);
|
|
1418
|
+
const { url } = await getGitHubOAuthUrl({ redirectUri, state });
|
|
1419
|
+
window.location.href = url;
|
|
1420
|
+
} catch (error) {
|
|
1421
|
+
setIsLoading(false);
|
|
1422
|
+
if (onError) {
|
|
1423
|
+
onError(error instanceof Error ? error : new Error("Failed to start GitHub OAuth"));
|
|
1424
|
+
}
|
|
1425
|
+
}
|
|
1426
|
+
}, [getGitHubOAuthUrl, redirectUri, onError, isLoading, disabled]);
|
|
1427
|
+
const baseStyles = "githat-github-button";
|
|
1428
|
+
const variantStyles = variant === "outline" ? "githat-github-button-outline" : "";
|
|
1429
|
+
const disabledStyles = disabled || isLoading ? "githat-github-button-disabled" : "";
|
|
1430
|
+
return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(
|
|
1431
|
+
"button",
|
|
1432
|
+
{
|
|
1433
|
+
type: "button",
|
|
1434
|
+
onClick: handleClick,
|
|
1435
|
+
disabled: disabled || isLoading,
|
|
1436
|
+
className: `${baseStyles} ${variantStyles} ${disabledStyles} ${className}`.trim(),
|
|
1437
|
+
children: [
|
|
1438
|
+
isLoading ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("span", { className: "githat-github-spinner" }) : /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(GitHubIcon, {}),
|
|
1439
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)("span", { children })
|
|
1440
|
+
]
|
|
1441
|
+
}
|
|
1442
|
+
);
|
|
1443
|
+
}
|
|
1444
|
+
if (typeof document !== "undefined") {
|
|
1445
|
+
const styleId = "githat-github-button-styles";
|
|
1446
|
+
if (!document.getElementById(styleId)) {
|
|
1447
|
+
const style = document.createElement("style");
|
|
1448
|
+
style.id = styleId;
|
|
1449
|
+
style.textContent = `
|
|
1450
|
+
.githat-github-button {
|
|
1451
|
+
display: inline-flex;
|
|
1452
|
+
align-items: center;
|
|
1453
|
+
justify-content: center;
|
|
1454
|
+
gap: 0.5rem;
|
|
1455
|
+
padding: 0.625rem 1rem;
|
|
1456
|
+
font-size: 0.875rem;
|
|
1457
|
+
font-weight: 500;
|
|
1458
|
+
border-radius: 0.375rem;
|
|
1459
|
+
border: none;
|
|
1460
|
+
cursor: pointer;
|
|
1461
|
+
transition: all 0.15s ease;
|
|
1462
|
+
background-color: #24292f;
|
|
1463
|
+
color: #ffffff;
|
|
1464
|
+
width: 100%;
|
|
1465
|
+
}
|
|
1466
|
+
.githat-github-button:hover:not(:disabled) {
|
|
1467
|
+
background-color: #32383f;
|
|
1468
|
+
}
|
|
1469
|
+
.githat-github-button-outline {
|
|
1470
|
+
background-color: transparent;
|
|
1471
|
+
color: #24292f;
|
|
1472
|
+
border: 1px solid #d0d7de;
|
|
1473
|
+
}
|
|
1474
|
+
.githat-github-button-outline:hover:not(:disabled) {
|
|
1475
|
+
background-color: #f6f8fa;
|
|
1476
|
+
border-color: #24292f;
|
|
1477
|
+
}
|
|
1478
|
+
.githat-github-button-disabled {
|
|
1479
|
+
opacity: 0.5;
|
|
1480
|
+
cursor: not-allowed;
|
|
1481
|
+
}
|
|
1482
|
+
.githat-github-spinner {
|
|
1483
|
+
width: 1rem;
|
|
1484
|
+
height: 1rem;
|
|
1485
|
+
border: 2px solid currentColor;
|
|
1486
|
+
border-top-color: transparent;
|
|
1487
|
+
border-radius: 50%;
|
|
1488
|
+
animation: githat-spin 0.6s linear infinite;
|
|
1489
|
+
}
|
|
1490
|
+
@keyframes githat-spin {
|
|
1491
|
+
to { transform: rotate(360deg); }
|
|
1492
|
+
}
|
|
1493
|
+
`;
|
|
1494
|
+
document.head.appendChild(style);
|
|
1495
|
+
}
|
|
1496
|
+
}
|
|
1497
|
+
|
|
1498
|
+
// src/components/GitHubCallback.tsx
|
|
1499
|
+
var import_react16 = require("react");
|
|
1500
|
+
var import_jsx_runtime15 = require("react/jsx-runtime");
|
|
1501
|
+
function GitHubCallback({
|
|
1502
|
+
redirectUrl = "/dashboard",
|
|
1503
|
+
newUserRedirectUrl,
|
|
1504
|
+
onSuccess,
|
|
1505
|
+
onError,
|
|
1506
|
+
loadingComponent,
|
|
1507
|
+
errorComponent
|
|
1508
|
+
}) {
|
|
1509
|
+
const { signInWithGitHub } = useGitHat();
|
|
1510
|
+
const { config } = useAuth();
|
|
1511
|
+
const [error, setError] = (0, import_react16.useState)(null);
|
|
1512
|
+
const [isProcessing, setIsProcessing] = (0, import_react16.useState)(true);
|
|
1513
|
+
(0, import_react16.useEffect)(() => {
|
|
1514
|
+
const handleCallback = async () => {
|
|
1515
|
+
const params = new URLSearchParams(window.location.search);
|
|
1516
|
+
const code = params.get("code");
|
|
1517
|
+
const state = params.get("state");
|
|
1518
|
+
const errorParam = params.get("error");
|
|
1519
|
+
const errorDescription = params.get("error_description");
|
|
1520
|
+
if (errorParam) {
|
|
1521
|
+
const errorMsg = errorDescription || errorParam;
|
|
1522
|
+
setError(errorMsg);
|
|
1523
|
+
setIsProcessing(false);
|
|
1524
|
+
if (onError) {
|
|
1525
|
+
onError(new Error(errorMsg));
|
|
1526
|
+
}
|
|
1527
|
+
return;
|
|
1528
|
+
}
|
|
1529
|
+
if (!code) {
|
|
1530
|
+
const errorMsg = "No authorization code received";
|
|
1531
|
+
setError(errorMsg);
|
|
1532
|
+
setIsProcessing(false);
|
|
1533
|
+
if (onError) {
|
|
1534
|
+
onError(new Error(errorMsg));
|
|
1535
|
+
}
|
|
1536
|
+
return;
|
|
1537
|
+
}
|
|
1538
|
+
const savedState = sessionStorage.getItem("githat_oauth_state");
|
|
1539
|
+
if (savedState && state !== savedState) {
|
|
1540
|
+
const errorMsg = "Invalid state parameter";
|
|
1541
|
+
setError(errorMsg);
|
|
1542
|
+
setIsProcessing(false);
|
|
1543
|
+
if (onError) {
|
|
1544
|
+
onError(new Error(errorMsg));
|
|
1545
|
+
}
|
|
1546
|
+
return;
|
|
1547
|
+
}
|
|
1548
|
+
sessionStorage.removeItem("githat_oauth_state");
|
|
1549
|
+
try {
|
|
1550
|
+
const result = await signInWithGitHub(code);
|
|
1551
|
+
if (onSuccess) {
|
|
1552
|
+
onSuccess(result);
|
|
1553
|
+
}
|
|
1554
|
+
const targetUrl = result.isNewUser && newUserRedirectUrl ? newUserRedirectUrl : redirectUrl || config.afterSignInUrl || "/dashboard";
|
|
1555
|
+
window.location.href = targetUrl;
|
|
1556
|
+
} catch (err) {
|
|
1557
|
+
const errorMsg = err instanceof Error ? err.message : "Authentication failed";
|
|
1558
|
+
setError(errorMsg);
|
|
1559
|
+
setIsProcessing(false);
|
|
1560
|
+
if (onError) {
|
|
1561
|
+
onError(err instanceof Error ? err : new Error(errorMsg));
|
|
1562
|
+
}
|
|
1563
|
+
}
|
|
1564
|
+
};
|
|
1565
|
+
handleCallback();
|
|
1566
|
+
}, [signInWithGitHub, redirectUrl, newUserRedirectUrl, config.afterSignInUrl, onSuccess, onError]);
|
|
1567
|
+
if (error) {
|
|
1568
|
+
if (errorComponent) {
|
|
1569
|
+
return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_jsx_runtime15.Fragment, { children: errorComponent(error) });
|
|
1570
|
+
}
|
|
1571
|
+
return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("div", { className: "githat-callback-error", children: [
|
|
1572
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)("h2", { children: "Authentication Failed" }),
|
|
1573
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)("p", { children: error }),
|
|
1574
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)("a", { href: "/sign-in", children: "Back to Sign In" })
|
|
1575
|
+
] });
|
|
1576
|
+
}
|
|
1577
|
+
if (loadingComponent) {
|
|
1578
|
+
return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_jsx_runtime15.Fragment, { children: loadingComponent });
|
|
1579
|
+
}
|
|
1580
|
+
return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("div", { className: "githat-callback-loading", children: [
|
|
1581
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)("div", { className: "githat-callback-spinner" }),
|
|
1582
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)("p", { children: "Completing sign in with GitHub..." })
|
|
1583
|
+
] });
|
|
1584
|
+
}
|
|
1585
|
+
if (typeof document !== "undefined") {
|
|
1586
|
+
const styleId = "githat-callback-styles";
|
|
1587
|
+
if (!document.getElementById(styleId)) {
|
|
1588
|
+
const style = document.createElement("style");
|
|
1589
|
+
style.id = styleId;
|
|
1590
|
+
style.textContent = `
|
|
1591
|
+
.githat-callback-loading,
|
|
1592
|
+
.githat-callback-error {
|
|
1593
|
+
display: flex;
|
|
1594
|
+
flex-direction: column;
|
|
1595
|
+
align-items: center;
|
|
1596
|
+
justify-content: center;
|
|
1597
|
+
min-height: 200px;
|
|
1598
|
+
padding: 2rem;
|
|
1599
|
+
text-align: center;
|
|
1600
|
+
}
|
|
1601
|
+
.githat-callback-spinner {
|
|
1602
|
+
width: 2rem;
|
|
1603
|
+
height: 2rem;
|
|
1604
|
+
border: 3px solid #e5e7eb;
|
|
1605
|
+
border-top-color: #3b82f6;
|
|
1606
|
+
border-radius: 50%;
|
|
1607
|
+
animation: githat-spin 0.8s linear infinite;
|
|
1608
|
+
margin-bottom: 1rem;
|
|
1609
|
+
}
|
|
1610
|
+
.githat-callback-error h2 {
|
|
1611
|
+
color: #dc2626;
|
|
1612
|
+
margin-bottom: 0.5rem;
|
|
1613
|
+
}
|
|
1614
|
+
.githat-callback-error p {
|
|
1615
|
+
color: #6b7280;
|
|
1616
|
+
margin-bottom: 1rem;
|
|
1617
|
+
}
|
|
1618
|
+
.githat-callback-error a {
|
|
1619
|
+
color: #3b82f6;
|
|
1620
|
+
text-decoration: underline;
|
|
1621
|
+
}
|
|
1622
|
+
@keyframes githat-spin {
|
|
1623
|
+
to { transform: rotate(360deg); }
|
|
1624
|
+
}
|
|
1625
|
+
`;
|
|
1626
|
+
document.head.appendChild(style);
|
|
1627
|
+
}
|
|
1628
|
+
}
|
|
1629
|
+
|
|
1630
|
+
// src/components/CognitoButton.tsx
|
|
1631
|
+
var import_react17 = require("react");
|
|
1632
|
+
var import_jsx_runtime16 = require("react/jsx-runtime");
|
|
1633
|
+
var AWSIcon = () => /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("svg", { width: "20", height: "20", viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("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" }) });
|
|
1634
|
+
function CognitoButton({
|
|
1635
|
+
children = "Continue with AWS",
|
|
1636
|
+
redirectUri,
|
|
1637
|
+
identityProvider,
|
|
1638
|
+
onError,
|
|
1639
|
+
className = "",
|
|
1640
|
+
variant = "default",
|
|
1641
|
+
disabled = false
|
|
1642
|
+
}) {
|
|
1643
|
+
const { getCognitoOAuthUrl } = useGitHat();
|
|
1644
|
+
const [isLoading, setIsLoading] = (0, import_react17.useState)(false);
|
|
1645
|
+
const handleClick = (0, import_react17.useCallback)(async () => {
|
|
1646
|
+
if (isLoading || disabled) return;
|
|
1647
|
+
setIsLoading(true);
|
|
1648
|
+
try {
|
|
1649
|
+
const state = crypto.randomUUID();
|
|
1650
|
+
sessionStorage.setItem("githat_cognito_oauth_state", state);
|
|
1651
|
+
const { url } = await getCognitoOAuthUrl({ redirectUri, state, identityProvider });
|
|
1652
|
+
window.location.href = url;
|
|
1653
|
+
} catch (error) {
|
|
1654
|
+
setIsLoading(false);
|
|
1655
|
+
if (onError) {
|
|
1656
|
+
onError(error instanceof Error ? error : new Error("Failed to start Cognito OAuth"));
|
|
1657
|
+
}
|
|
1658
|
+
}
|
|
1659
|
+
}, [getCognitoOAuthUrl, redirectUri, identityProvider, onError, isLoading, disabled]);
|
|
1660
|
+
const baseStyles = "githat-cognito-button";
|
|
1661
|
+
const variantStyles = variant === "outline" ? "githat-cognito-button-outline" : "";
|
|
1662
|
+
const disabledStyles = disabled || isLoading ? "githat-cognito-button-disabled" : "";
|
|
1663
|
+
return /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)(
|
|
1664
|
+
"button",
|
|
1665
|
+
{
|
|
1666
|
+
type: "button",
|
|
1667
|
+
onClick: handleClick,
|
|
1668
|
+
disabled: disabled || isLoading,
|
|
1669
|
+
className: `${baseStyles} ${variantStyles} ${disabledStyles} ${className}`.trim(),
|
|
1670
|
+
children: [
|
|
1671
|
+
isLoading ? /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("span", { className: "githat-cognito-spinner" }) : /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(AWSIcon, {}),
|
|
1672
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)("span", { children })
|
|
1673
|
+
]
|
|
1674
|
+
}
|
|
1675
|
+
);
|
|
1676
|
+
}
|
|
1677
|
+
if (typeof document !== "undefined") {
|
|
1678
|
+
const styleId = "githat-cognito-button-styles";
|
|
1679
|
+
if (!document.getElementById(styleId)) {
|
|
1680
|
+
const style = document.createElement("style");
|
|
1681
|
+
style.id = styleId;
|
|
1682
|
+
style.textContent = `
|
|
1683
|
+
.githat-cognito-button {
|
|
1684
|
+
display: inline-flex;
|
|
1685
|
+
align-items: center;
|
|
1686
|
+
justify-content: center;
|
|
1687
|
+
gap: 0.5rem;
|
|
1688
|
+
padding: 0.625rem 1rem;
|
|
1689
|
+
font-size: 0.875rem;
|
|
1690
|
+
font-weight: 500;
|
|
1691
|
+
border-radius: 0.375rem;
|
|
1692
|
+
border: none;
|
|
1693
|
+
cursor: pointer;
|
|
1694
|
+
transition: all 0.15s ease;
|
|
1695
|
+
background-color: #ff9900;
|
|
1696
|
+
color: #232f3e;
|
|
1697
|
+
width: 100%;
|
|
1698
|
+
}
|
|
1699
|
+
.githat-cognito-button:hover:not(:disabled) {
|
|
1700
|
+
background-color: #ec7211;
|
|
1701
|
+
}
|
|
1702
|
+
.githat-cognito-button-outline {
|
|
1703
|
+
background-color: transparent;
|
|
1704
|
+
color: #ff9900;
|
|
1705
|
+
border: 1px solid #ff9900;
|
|
1706
|
+
}
|
|
1707
|
+
.githat-cognito-button-outline:hover:not(:disabled) {
|
|
1708
|
+
background-color: rgba(255, 153, 0, 0.1);
|
|
1709
|
+
}
|
|
1710
|
+
.githat-cognito-button-disabled {
|
|
1711
|
+
opacity: 0.5;
|
|
1712
|
+
cursor: not-allowed;
|
|
1713
|
+
}
|
|
1714
|
+
.githat-cognito-spinner {
|
|
1715
|
+
width: 1rem;
|
|
1716
|
+
height: 1rem;
|
|
1717
|
+
border: 2px solid currentColor;
|
|
1718
|
+
border-top-color: transparent;
|
|
1719
|
+
border-radius: 50%;
|
|
1720
|
+
animation: githat-cognito-spin 0.6s linear infinite;
|
|
1721
|
+
}
|
|
1722
|
+
@keyframes githat-cognito-spin {
|
|
1723
|
+
to { transform: rotate(360deg); }
|
|
1724
|
+
}
|
|
1725
|
+
`;
|
|
1726
|
+
document.head.appendChild(style);
|
|
1727
|
+
}
|
|
1728
|
+
}
|
|
1729
|
+
|
|
1730
|
+
// src/components/CognitoCallback.tsx
|
|
1731
|
+
var import_react18 = require("react");
|
|
1732
|
+
var import_jsx_runtime17 = require("react/jsx-runtime");
|
|
1733
|
+
function CognitoCallback({
|
|
1734
|
+
redirectUrl = "/dashboard",
|
|
1735
|
+
newUserRedirectUrl,
|
|
1736
|
+
onSuccess,
|
|
1737
|
+
onError,
|
|
1738
|
+
loadingComponent,
|
|
1739
|
+
errorComponent
|
|
1740
|
+
}) {
|
|
1741
|
+
const { signInWithCognito } = useGitHat();
|
|
1742
|
+
const { config } = useAuth();
|
|
1743
|
+
const [error, setError] = (0, import_react18.useState)(null);
|
|
1744
|
+
const [isProcessing, setIsProcessing] = (0, import_react18.useState)(true);
|
|
1745
|
+
(0, import_react18.useEffect)(() => {
|
|
1746
|
+
const handleCallback = async () => {
|
|
1747
|
+
const params = new URLSearchParams(window.location.search);
|
|
1748
|
+
const code = params.get("code");
|
|
1749
|
+
const state = params.get("state");
|
|
1750
|
+
const errorParam = params.get("error");
|
|
1751
|
+
const errorDescription = params.get("error_description");
|
|
1752
|
+
if (errorParam) {
|
|
1753
|
+
const errorMsg = errorDescription || errorParam;
|
|
1754
|
+
setError(errorMsg);
|
|
1755
|
+
setIsProcessing(false);
|
|
1756
|
+
if (onError) {
|
|
1757
|
+
onError(new Error(errorMsg));
|
|
1758
|
+
}
|
|
1759
|
+
return;
|
|
1760
|
+
}
|
|
1761
|
+
if (!code) {
|
|
1762
|
+
const errorMsg = "No authorization code received";
|
|
1763
|
+
setError(errorMsg);
|
|
1764
|
+
setIsProcessing(false);
|
|
1765
|
+
if (onError) {
|
|
1766
|
+
onError(new Error(errorMsg));
|
|
1767
|
+
}
|
|
1768
|
+
return;
|
|
1769
|
+
}
|
|
1770
|
+
const savedState = sessionStorage.getItem("githat_cognito_oauth_state");
|
|
1771
|
+
if (savedState && state !== savedState) {
|
|
1772
|
+
const errorMsg = "Invalid state parameter";
|
|
1773
|
+
setError(errorMsg);
|
|
1774
|
+
setIsProcessing(false);
|
|
1775
|
+
if (onError) {
|
|
1776
|
+
onError(new Error(errorMsg));
|
|
1777
|
+
}
|
|
1778
|
+
return;
|
|
1779
|
+
}
|
|
1780
|
+
sessionStorage.removeItem("githat_cognito_oauth_state");
|
|
1781
|
+
try {
|
|
1782
|
+
const result = await signInWithCognito(code);
|
|
1783
|
+
if (onSuccess) {
|
|
1784
|
+
onSuccess(result);
|
|
1785
|
+
}
|
|
1786
|
+
const targetUrl = result.isNewUser && newUserRedirectUrl ? newUserRedirectUrl : redirectUrl || config.afterSignInUrl || "/dashboard";
|
|
1787
|
+
window.location.href = targetUrl;
|
|
1788
|
+
} catch (err) {
|
|
1789
|
+
const errorMsg = err instanceof Error ? err.message : "Authentication failed";
|
|
1790
|
+
setError(errorMsg);
|
|
1791
|
+
setIsProcessing(false);
|
|
1792
|
+
if (onError) {
|
|
1793
|
+
onError(err instanceof Error ? err : new Error(errorMsg));
|
|
1794
|
+
}
|
|
1795
|
+
}
|
|
1796
|
+
};
|
|
1797
|
+
handleCallback();
|
|
1798
|
+
}, [signInWithCognito, redirectUrl, newUserRedirectUrl, config.afterSignInUrl, onSuccess, onError]);
|
|
1799
|
+
if (error) {
|
|
1800
|
+
if (errorComponent) {
|
|
1801
|
+
return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(import_jsx_runtime17.Fragment, { children: errorComponent(error) });
|
|
1802
|
+
}
|
|
1803
|
+
return /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("div", { className: "githat-callback-error", children: [
|
|
1804
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)("h2", { children: "Authentication Failed" }),
|
|
1805
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)("p", { children: error }),
|
|
1806
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)("a", { href: "/sign-in", children: "Back to Sign In" })
|
|
1807
|
+
] });
|
|
1808
|
+
}
|
|
1809
|
+
if (loadingComponent) {
|
|
1810
|
+
return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(import_jsx_runtime17.Fragment, { children: loadingComponent });
|
|
1811
|
+
}
|
|
1812
|
+
return /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("div", { className: "githat-callback-loading", children: [
|
|
1813
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)("div", { className: "githat-callback-spinner" }),
|
|
1814
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)("p", { children: "Completing sign in with AWS Cognito..." })
|
|
1815
|
+
] });
|
|
1816
|
+
}
|
|
1320
1817
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1321
1818
|
0 && (module.exports = {
|
|
1322
1819
|
ChangePasswordForm,
|
|
1820
|
+
CognitoButton,
|
|
1821
|
+
CognitoCallback,
|
|
1323
1822
|
ForgotPasswordForm,
|
|
1324
1823
|
GitHatProvider,
|
|
1824
|
+
GitHubButton,
|
|
1825
|
+
GitHubCallback,
|
|
1325
1826
|
OrgSwitcher,
|
|
1326
1827
|
ProtectedRoute,
|
|
1327
1828
|
ResetPasswordForm,
|