@stack-spot/auth-react 1.2.4 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/out/index.d.ts +35 -1
- package/out/index.js +196 -37
- package/out/index.js.map +1 -1
- package/out/index.mjs +192 -35
- package/out/index.mjs.map +1 -1
- package/package.json +16 -9
- package/src/Authenticated.tsx +58 -0
- package/src/Login.tsx +163 -0
- package/src/index.ts +3 -0
- package/src/utils/cookies.ts +5 -24
- package/src/utils/redirect.ts +0 -2
- package/tsconfig.json +7 -2
- package/src/utils/regex.ts +0 -1
package/out/index.d.ts
CHANGED
|
@@ -1,5 +1,39 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
1
2
|
import { Session, ThirdPartyLoginParams, AuthConfig, ThirdPartyAuthType } from '@stack-spot/auth';
|
|
2
3
|
|
|
4
|
+
type LoginType = 'sso' | 'idp';
|
|
5
|
+
interface BaseData {
|
|
6
|
+
type: LoginType;
|
|
7
|
+
}
|
|
8
|
+
interface SSOData extends BaseData {
|
|
9
|
+
type: 'sso';
|
|
10
|
+
email: string;
|
|
11
|
+
}
|
|
12
|
+
interface IDPData extends BaseData {
|
|
13
|
+
type: 'idp';
|
|
14
|
+
provider: 'external-idp:github';
|
|
15
|
+
}
|
|
16
|
+
type LoginData = SSOData | IDPData;
|
|
17
|
+
type LoginProps = {
|
|
18
|
+
initialValue?: string;
|
|
19
|
+
onSubmit: (data: LoginData) => Promise<void>;
|
|
20
|
+
welcomeText?: string;
|
|
21
|
+
removeLoadingOnSuccess?: boolean;
|
|
22
|
+
className?: string;
|
|
23
|
+
style?: React.CSSProperties;
|
|
24
|
+
banner?: React.ReactNode;
|
|
25
|
+
loginTypes?: LoginType[];
|
|
26
|
+
};
|
|
27
|
+
declare const Login: ({ onSubmit, initialValue, welcomeText, removeLoadingOnSuccess, className, style, banner, loginTypes }: LoginProps) => react_jsx_runtime.JSX.Element;
|
|
28
|
+
|
|
29
|
+
interface Props {
|
|
30
|
+
children: React.ReactElement;
|
|
31
|
+
onLogin?: () => void;
|
|
32
|
+
onSession?: () => void;
|
|
33
|
+
customLoginProps?: Omit<LoginProps, 'onSubmit' | 'initialValue'>;
|
|
34
|
+
}
|
|
35
|
+
declare const Authenticated: ({ children, onLogin, onSession, customLoginProps }: Props) => react_jsx_runtime.JSX.Element | null;
|
|
36
|
+
|
|
3
37
|
interface SessionManagerConfig extends Pick<AuthConfig, 'accountUrl' | 'authUrl' | 'clientId' | 'defaultTenant' | 'redirectUrl'> {
|
|
4
38
|
loginUrl: string;
|
|
5
39
|
blockedAuthTypes?: ThirdPartyAuthType[];
|
|
@@ -40,4 +74,4 @@ declare class SessionManager {
|
|
|
40
74
|
|
|
41
75
|
declare function useSession(): Session | undefined;
|
|
42
76
|
|
|
43
|
-
export { SessionManager, useSession };
|
|
77
|
+
export { Authenticated, Login, SessionManager, useSession };
|
package/out/index.js
CHANGED
|
@@ -1,38 +1,142 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
4
|
+
var core = require('@citric/core');
|
|
5
|
+
var portalComponents = require('@stack-spot/portal-components');
|
|
6
|
+
var portalTheme = require('@stack-spot/portal-theme');
|
|
7
|
+
require('@stack-spot/portal-theme/dist/theme.css');
|
|
8
|
+
var portalTranslate = require('@stack-spot/portal-translate');
|
|
4
9
|
var react = require('react');
|
|
10
|
+
var icons = require('@citric/icons');
|
|
11
|
+
var ui = require('@citric/ui');
|
|
12
|
+
var svg = require('@stack-spot/portal-components/svg');
|
|
13
|
+
var styledComponents = require('styled-components');
|
|
14
|
+
var auth = require('@stack-spot/auth');
|
|
15
|
+
|
|
16
|
+
const LoginBox = styledComponents.styled.form`
|
|
17
|
+
display: flex;
|
|
18
|
+
flex-direction: column;
|
|
19
|
+
justify-content: center;
|
|
20
|
+
gap: 24px;
|
|
21
|
+
|
|
22
|
+
header {
|
|
23
|
+
display: flex;
|
|
24
|
+
flex-direction: column;
|
|
25
|
+
align-items: center;
|
|
26
|
+
gap: 24px;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.title {
|
|
30
|
+
font-size: 1rem;
|
|
31
|
+
}
|
|
5
32
|
|
|
6
|
-
|
|
33
|
+
.separator {
|
|
34
|
+
padding: 0 8px;
|
|
35
|
+
background-color: ${portalTheme.theme.color.light["400"]};
|
|
36
|
+
color: ${portalTheme.theme.color.light["700"]};
|
|
37
|
+
display: flex;
|
|
38
|
+
flex-direction: row;
|
|
39
|
+
align-items: center;
|
|
40
|
+
justify-content: center;
|
|
41
|
+
gap: 20px;
|
|
42
|
+
margin: 0;
|
|
7
43
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
44
|
+
&:before, &:after {
|
|
45
|
+
content: '';
|
|
46
|
+
height: 1px;
|
|
47
|
+
flex: 1;
|
|
48
|
+
background-color: ${portalTheme.theme.color.light["600"]};
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.error {
|
|
53
|
+
color: ${portalTheme.theme.color.danger["500"]};
|
|
54
|
+
line-height: 1.5rem;
|
|
55
|
+
}
|
|
56
|
+
`;
|
|
57
|
+
const Login = ({ onSubmit, initialValue = "", welcomeText, removeLoadingOnSuccess, className, style, banner, loginTypes = ["idp", "sso"] }) => {
|
|
58
|
+
const t = portalTranslate.useTranslate(dictionary);
|
|
59
|
+
const searchParams = new URLSearchParams(location.search);
|
|
60
|
+
const [error, setError] = react.useState(searchParams.get("error_description") || searchParams.get("error") || "");
|
|
61
|
+
const [loading, setLoading] = react.useState(false);
|
|
62
|
+
const [email, setEmail] = react.useState(initialValue);
|
|
63
|
+
const disabled = !email.match(/\w+@\w+/);
|
|
64
|
+
const idpLoginEnabled = loginTypes.includes("idp");
|
|
65
|
+
const ssoLoginEnabled = loginTypes.includes("sso");
|
|
66
|
+
async function login(type) {
|
|
67
|
+
setError("");
|
|
68
|
+
setLoading(true);
|
|
69
|
+
try {
|
|
70
|
+
const data = type === "sso" ? { type: "sso", email } : { type: "idp", provider: "external-idp:github" };
|
|
71
|
+
await onSubmit(data);
|
|
72
|
+
if (removeLoadingOnSuccess)
|
|
73
|
+
setLoading(false);
|
|
74
|
+
} catch (error2) {
|
|
75
|
+
setLoading(false);
|
|
76
|
+
setError(error2.message || error2.toString());
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
function submitForm(e) {
|
|
80
|
+
e.preventDefault();
|
|
81
|
+
if (disabled)
|
|
82
|
+
return;
|
|
83
|
+
login("sso");
|
|
84
|
+
}
|
|
85
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
86
|
+
/* @__PURE__ */ jsxRuntime.jsxs(LoginBox, { onSubmit: submitForm, className, style, children: [
|
|
87
|
+
/* @__PURE__ */ jsxRuntime.jsxs("header", { children: [
|
|
88
|
+
/* @__PURE__ */ jsxRuntime.jsx(svg.MiniLogo, {}),
|
|
89
|
+
/* @__PURE__ */ jsxRuntime.jsx(core.Text, { className: "title", children: welcomeText || t.welcome })
|
|
90
|
+
] }),
|
|
91
|
+
ssoLoginEnabled && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
92
|
+
/* @__PURE__ */ jsxRuntime.jsx(core.Input, { name: "email", value: email, onChange: (e) => setEmail(e.target.value), placeholder: t.placeholder }),
|
|
93
|
+
/* @__PURE__ */ jsxRuntime.jsx(core.Button, { colorScheme: "primary", disabled: disabled || loading, children: loading ? /* @__PURE__ */ jsxRuntime.jsx(ui.LoadingCircular, {}) : /* @__PURE__ */ jsxRuntime.jsx(core.Text, { children: t.continue }) })
|
|
94
|
+
] }),
|
|
95
|
+
ssoLoginEnabled && idpLoginEnabled && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "separator", children: t.or }),
|
|
96
|
+
idpLoginEnabled && /* @__PURE__ */ jsxRuntime.jsx(core.Button, { colorScheme: "light", type: "button", onClick: () => login("idp"), disabled: loading, children: loading ? /* @__PURE__ */ jsxRuntime.jsx(ui.LoadingCircular, {}) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
97
|
+
/* @__PURE__ */ jsxRuntime.jsx(core.IconBox, { children: /* @__PURE__ */ jsxRuntime.jsx(icons.Github, {}) }),
|
|
98
|
+
/* @__PURE__ */ jsxRuntime.jsx(core.Text, { children: t.loginWithGithub })
|
|
99
|
+
] }) }),
|
|
100
|
+
error && /* @__PURE__ */ jsxRuntime.jsxs(core.Text, { className: "error", children: [
|
|
101
|
+
t.error,
|
|
102
|
+
": ",
|
|
103
|
+
error
|
|
104
|
+
] })
|
|
105
|
+
] }),
|
|
106
|
+
banner ? /* @__PURE__ */ jsxRuntime.jsx(portalComponents.BannerWarning, { children: banner }) : null
|
|
107
|
+
] });
|
|
15
108
|
};
|
|
16
|
-
const
|
|
17
|
-
|
|
109
|
+
const dictionary = {
|
|
110
|
+
en: {
|
|
111
|
+
welcome: "Welcome to StackSpot",
|
|
112
|
+
placeholder: "your@email.com",
|
|
113
|
+
continue: "Continue",
|
|
114
|
+
or: "or",
|
|
115
|
+
loginWithGithub: "Login with Github",
|
|
116
|
+
error: "Error while attempting to login"
|
|
117
|
+
},
|
|
118
|
+
pt: {
|
|
119
|
+
welcome: "Bem vindo \xE0 StackSpot",
|
|
120
|
+
placeholder: "nome@email.com",
|
|
121
|
+
continue: "Continuar",
|
|
122
|
+
or: "ou",
|
|
123
|
+
loginWithGithub: "Logar com o GitHub",
|
|
124
|
+
error: "Erro ao fazer login"
|
|
125
|
+
}
|
|
18
126
|
};
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
const [name, ...value] = current.split("=");
|
|
22
|
-
prev[name] = value.join("=");
|
|
23
|
-
return prev;
|
|
24
|
-
}, {});
|
|
127
|
+
|
|
128
|
+
const sessionKey$1 = `stk-session${portalComponents.getCookieDomain()}`;
|
|
25
129
|
const sessionCookie = Object.freeze({
|
|
26
|
-
set: (data) => setCookie(sessionKey$1, JSON.stringify(data)),
|
|
130
|
+
set: (data) => portalComponents.setCookie(sessionKey$1, JSON.stringify(data)),
|
|
27
131
|
get: () => {
|
|
28
132
|
try {
|
|
29
|
-
const cookie = getCookie(sessionKey$1);
|
|
133
|
+
const cookie = portalComponents.getCookie(sessionKey$1);
|
|
30
134
|
return cookie ? JSON.parse(cookie) : void 0;
|
|
31
135
|
} catch (error) {
|
|
32
136
|
console.error(error);
|
|
33
137
|
}
|
|
34
138
|
},
|
|
35
|
-
delete: () => removeCookie(sessionKey$1)
|
|
139
|
+
delete: () => portalComponents.removeCookie(sessionKey$1)
|
|
36
140
|
});
|
|
37
141
|
|
|
38
142
|
const redirect = async (url) => {
|
|
@@ -40,27 +144,27 @@ const redirect = async (url) => {
|
|
|
40
144
|
await new Promise(() => "");
|
|
41
145
|
};
|
|
42
146
|
|
|
43
|
-
var __defProp = Object.defineProperty;
|
|
44
|
-
var __defProps = Object.defineProperties;
|
|
45
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
46
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
47
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
48
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
49
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
50
|
-
var __spreadValues = (a, b) => {
|
|
147
|
+
var __defProp$1 = Object.defineProperty;
|
|
148
|
+
var __defProps$1 = Object.defineProperties;
|
|
149
|
+
var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
|
|
150
|
+
var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
|
|
151
|
+
var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
|
|
152
|
+
var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
|
|
153
|
+
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
154
|
+
var __spreadValues$1 = (a, b) => {
|
|
51
155
|
for (var prop in b || (b = {}))
|
|
52
|
-
if (__hasOwnProp.call(b, prop))
|
|
53
|
-
__defNormalProp(a, prop, b[prop]);
|
|
54
|
-
if (__getOwnPropSymbols)
|
|
55
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
56
|
-
if (__propIsEnum.call(b, prop))
|
|
57
|
-
__defNormalProp(a, prop, b[prop]);
|
|
156
|
+
if (__hasOwnProp$1.call(b, prop))
|
|
157
|
+
__defNormalProp$1(a, prop, b[prop]);
|
|
158
|
+
if (__getOwnPropSymbols$1)
|
|
159
|
+
for (var prop of __getOwnPropSymbols$1(b)) {
|
|
160
|
+
if (__propIsEnum$1.call(b, prop))
|
|
161
|
+
__defNormalProp$1(a, prop, b[prop]);
|
|
58
162
|
}
|
|
59
163
|
return a;
|
|
60
164
|
};
|
|
61
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
165
|
+
var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
|
|
62
166
|
var __publicField = (obj, key, value) => {
|
|
63
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
167
|
+
__defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
64
168
|
return value;
|
|
65
169
|
};
|
|
66
170
|
const sessionKey = "session";
|
|
@@ -71,7 +175,7 @@ const _SessionManager = class _SessionManager {
|
|
|
71
175
|
__publicField(this, "config");
|
|
72
176
|
__publicField(this, "changeListeners", []);
|
|
73
177
|
this.config = config;
|
|
74
|
-
this.auth = new auth.AuthManager(__spreadProps(__spreadValues({}, config), {
|
|
178
|
+
this.auth = new auth.AuthManager(__spreadProps$1(__spreadValues$1({}, config), {
|
|
75
179
|
storage: localStorage,
|
|
76
180
|
sessionPersistence: {
|
|
77
181
|
load: () => localStorage.getItem(sessionKey),
|
|
@@ -226,6 +330,59 @@ ${error}`);
|
|
|
226
330
|
__publicField(_SessionManager, "instance");
|
|
227
331
|
let SessionManager = _SessionManager;
|
|
228
332
|
|
|
333
|
+
var __defProp = Object.defineProperty;
|
|
334
|
+
var __defProps = Object.defineProperties;
|
|
335
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
336
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
337
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
338
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
339
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
340
|
+
var __spreadValues = (a, b) => {
|
|
341
|
+
for (var prop in b || (b = {}))
|
|
342
|
+
if (__hasOwnProp.call(b, prop))
|
|
343
|
+
__defNormalProp(a, prop, b[prop]);
|
|
344
|
+
if (__getOwnPropSymbols)
|
|
345
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
346
|
+
if (__propIsEnum.call(b, prop))
|
|
347
|
+
__defNormalProp(a, prop, b[prop]);
|
|
348
|
+
}
|
|
349
|
+
return a;
|
|
350
|
+
};
|
|
351
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
352
|
+
const Authenticated = ({ children, onLogin, onSession, customLoginProps }) => {
|
|
353
|
+
const [authStatus, setAuthStatus] = react.useState("unknown");
|
|
354
|
+
const language = portalTranslate.useLanguage();
|
|
355
|
+
const sessionManager = SessionManager.instance;
|
|
356
|
+
portalComponents.useEffectOnce(() => {
|
|
357
|
+
async function checkAuth() {
|
|
358
|
+
await sessionManager.restoreSession();
|
|
359
|
+
if (sessionManager.urlHasThirdPartyLoginData()) {
|
|
360
|
+
await sessionManager.completeThirdPartyLogin();
|
|
361
|
+
onLogin == null ? void 0 : onLogin();
|
|
362
|
+
}
|
|
363
|
+
if (sessionManager.hasSession()) {
|
|
364
|
+
setAuthStatus("authenticated");
|
|
365
|
+
onSession == null ? void 0 : onSession();
|
|
366
|
+
} else {
|
|
367
|
+
setAuthStatus("unauthenticated");
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
checkAuth();
|
|
371
|
+
});
|
|
372
|
+
if (authStatus === "unknown")
|
|
373
|
+
return null;
|
|
374
|
+
if (authStatus === "authenticated")
|
|
375
|
+
return children;
|
|
376
|
+
return /* @__PURE__ */ jsxRuntime.jsx(portalTheme.CSSToCitricAdapter, { children: /* @__PURE__ */ jsxRuntime.jsx(core.Flex, { justifyContent: "center", alignItems: "center", flex: 1, style: { height: "100%" }, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
377
|
+
Login,
|
|
378
|
+
__spreadValues({
|
|
379
|
+
style: { width: "360px" },
|
|
380
|
+
onSubmit: (data) => sessionManager.startThirdPartyLogin(__spreadProps(__spreadValues({}, data), { locale: language })),
|
|
381
|
+
initialValue: sessionManager.getEmailForLogin()
|
|
382
|
+
}, customLoginProps || {})
|
|
383
|
+
) }) });
|
|
384
|
+
};
|
|
385
|
+
|
|
229
386
|
function useSession() {
|
|
230
387
|
const manager = SessionManager.instance;
|
|
231
388
|
const [session, setSession] = react.useState((manager == null ? void 0 : manager.hasSession()) ? manager.getSession() : void 0);
|
|
@@ -235,6 +392,8 @@ function useSession() {
|
|
|
235
392
|
return session;
|
|
236
393
|
}
|
|
237
394
|
|
|
395
|
+
exports.Authenticated = Authenticated;
|
|
396
|
+
exports.Login = Login;
|
|
238
397
|
exports.SessionManager = SessionManager;
|
|
239
398
|
exports.useSession = useSession;
|
|
240
399
|
//# sourceMappingURL=index.js.map
|
package/out/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/utils/regex.ts","../src/utils/cookies.ts","../src/utils/redirect.ts","../src/SessionManager.ts","../src/hooks.ts"],"sourcesContent":["export const DOMAIN_REGEX = new RegExp(/(\\.*(prd|stg|dev)*.stackspot.com)|localhost/)","import { ThirdPartyLoginParams } from \"@stack-spot/auth\"\nimport { DOMAIN_REGEX } from './regex'\n\nconst portalUrl = new URL(location.href)\nconst cookieDomain = DOMAIN_REGEX.exec(portalUrl.host)?.[0]\nconst defaultCookieAttributes = `domain=${cookieDomain}; SameSite=Strict;`\nconst sessionKey = `stk-session${cookieDomain}`\n\nconst setCookie = (key: string, value: string) => {\n document.cookie = `${key}=${value}; ${defaultCookieAttributes}`\n}\n\nconst removeCookie = (key: string) => {\n document.cookie = `${key}=; max-age=0; ${defaultCookieAttributes}`\n}\n\nconst getCookie = (key: string) => getCookies()[key]\n\nconst getCookies = (): Record<string, string> => document.cookie.split('; ').reduce((prev, current) => {\n const [name, ...value] = current.split('=')\n prev[name] = value.join('=')\n return prev\n}, {} as Record<string, string>)\n\n\ntype SessionCookie = ThirdPartyLoginParams & { sub: string }\nexport const sessionCookie = Object.freeze({\n set: (data: SessionCookie) => setCookie(sessionKey, JSON.stringify(data)),\n get: (): SessionCookie | undefined => {\n try {\n const cookie = getCookie(sessionKey)\n return cookie ? JSON.parse(cookie) : undefined\n } catch (error) {\n console.error(error)\n }\n },\n delete: () => removeCookie(sessionKey)\n})","\n\nexport const redirect = async (url: string) => {\n window.location.href = url\n /**\n * This is intentional. The promise bellow will never be fulfilled.\n * Once the set href is not instantaneous, this will guarantee no further code is executed until the user is really redirected.\n * Particularly useful to prevent flickering page renders on scenarios with redirects.\n */\n await new Promise(() => '')\n}","import { AuthConfig, AuthManager, Session, ThirdPartyAuthType, ThirdPartyLoginParams } from '@stack-spot/auth'\nimport { sessionCookie } from './utils/cookies'\nimport { redirect } from './utils/redirect'\n\nconst sessionKey = 'session'\n\ninterface SessionManagerConfig extends Pick<AuthConfig, 'accountUrl' | 'authUrl' | 'clientId' | 'defaultTenant' | 'redirectUrl'> {\n loginUrl: string,\n blockedAuthTypes?: ThirdPartyAuthType[]\n rdUrl?: string,\n}\n\ntype AuthExtraData = { from?: string | null, finalRedirect?: string | null }\n\ntype ChangeListener = (session: Session | undefined) => void\n\n/**\n * Controls the current session in a browser.\n * \n * This should not be used under a Node.JS environment.\n * \n * This is a singleton. To create the first instance or recover the current one, use `SessionManager.create`.\n */\nexport class SessionManager {\n private current: Session | undefined\n private readonly auth: AuthManager<AuthExtraData>\n private config: SessionManagerConfig\n private changeListeners: ChangeListener[] = []\n static instance: SessionManager\n\n private constructor(config: SessionManagerConfig) {\n this.config = config\n this.auth = new AuthManager<AuthExtraData>({\n ...config,\n storage: localStorage,\n sessionPersistence: {\n load: () => localStorage.getItem(sessionKey),\n save: (session) => localStorage.setItem(sessionKey, session),\n },\n })\n SessionManager.instance = this\n\n // Keep session in sync with other app's session\n addEventListener('focus', () => this.validateSharedSession())\n }\n\n static create(config: SessionManagerConfig) {\n return SessionManager.instance ?? new SessionManager(config)\n }\n\n private setSession(session: Session | undefined) {\n this.current = session\n this.changeListeners.forEach(l => l(session))\n if (session) this.setSessionCookie(session)\n }\n\n async restoreSession() {\n const session = await this.auth.restoreSession()\n const sessionValid = await this.validateSharedSession(session)\n this.setSession(sessionValid ? session : undefined)\n }\n\n async validateSharedSession(session: Session | undefined = this.current): Promise<boolean> {\n\n // skipping because authentication is in progress\n if (this.urlHasThirdPartyLoginData()) return false\n\n const sharedSessionCookie = sessionCookie.get()\n\n // It has been logged out on another portal, so logout on this one too\n if (!sharedSessionCookie) {\n session && await this.logout()\n return false\n }\n\n const isDifferentSessionActive = sharedSessionCookie.sub != session?.getTokenData().sub\n const isSharedSessionTypeBlocked = this.config.blockedAuthTypes?.includes(sharedSessionCookie.type)\n if (isSharedSessionTypeBlocked) return false\n else if (isDifferentSessionActive || !session) {\n await this.startThirdPartyLogin(sharedSessionCookie)\n return false\n }\n return true\n }\n\n hasSession() {\n return !!this.current && !this.current.isExpired()\n }\n\n getSession() {\n if (!this.hasSession()) {\n this.endSession()\n throw new Error('Session is not available, redirecting to login.')\n }\n return this.current!\n }\n\n async endSession(redirectToLogin = true) {\n this.current = undefined\n localStorage.removeItem(sessionKey)\n sessionCookie.delete()\n if (redirectToLogin) await redirect(this.config.loginUrl)\n }\n\n async logout() {\n try {\n await this.current?.logout()\n } catch (error) {\n // eslint-disable-next-line no-console\n console.error(`Could not logout from IDM.\\n${error}`)\n }\n await this.endSession()\n }\n\n async startThirdPartyLogin(data: ThirdPartyLoginParams) {\n const params = new URLSearchParams(location.search)\n const authUrl = await this.auth.startThirdPartyLogin(data, {\n from: location.href,\n finalRedirect: params.get('finalRedirect'),\n })\n await redirect(authUrl)\n }\n\n urlHasThirdPartyLoginData() {\n const url = new URL(location.toString())\n return url.searchParams.has('state') && !url.searchParams.has('error')\n }\n\n async completeThirdPartyLogin() {\n const url = new URL(location.toString())\n if (url.searchParams.has('error')) {\n throw new Error(`Error while signing in: ${url.searchParams.get('error_description')}`)\n }\n const { session, data: { from, finalRedirect } } = await this.auth.completeThirdPartyLogin(location.search)\n this.setSession(session)\n history.replaceState(null, '', from || location.toString().replace(/\\?.*$/, ''))\n this.sendLoginEventRd(this.current?.getTokenData().email, this.current?.getTokenData().name)\n if (finalRedirect) await redirect(finalRedirect)\n }\n\n getEmailForLogin() {\n const session = sessionCookie.get()\n return session?.type == 'sso' ? session.email : undefined\n }\n\n async switchAccount(accountId: string) {\n this.current && await this.auth.switchAccount(accountId, this.current)\n this.setSession(this.current)\n }\n\n onChange(listener: ChangeListener) {\n this.changeListeners.push(listener)\n return () => {\n const index = this.changeListeners.indexOf(listener)\n if (index != -1) this.changeListeners.splice(index, 1)\n }\n }\n\n private setSessionCookie(session: Session) {\n const { email, account_type, sub } = session.getTokenData()\n if (!email || !sub) return\n const isFreemium = account_type == 'FREEMIUM'\n if (isFreemium) {\n sessionCookie.set({ type: 'idp', provider: 'external-idp:github', sub })\n } else {\n sessionCookie.set({ email, type: 'sso', sub })\n }\n }\n\n private async sendLoginEventRd(email?: string, name?: string) {\n if (!this.config.rdUrl) return\n if (!email && !name) {\n // eslint-disable-next-line no-console\n console.error('Unable to trigger login hook. No sessionEmail or name identified.')\n return\n }\n\n const rdObject = {\n event_type: 'CONVERSION',\n event_family: 'CDP',\n payload: {\n email,\n name,\n conversion_identifier: 'login-v1',\n },\n }\n\n const response = await fetch(this.config.rdUrl, {\n method: 'POST',\n body: JSON.stringify(rdObject),\n headers: {\n 'content-type': 'application/json',\n },\n })\n const data = await response.json()\n\n if (!response.ok) {\n // eslint-disable-next-line no-console\n console.error('Error while sending event to RD Station', data)\n }\n }\n}\n","import { Session } from '@stack-spot/auth'\nimport { useEffect, useState } from 'react'\nimport { SessionManager } from './SessionManager'\n\nexport function useSession() {\n const manager = SessionManager.instance\n const [session, setSession] = useState<Session | undefined>(manager?.hasSession() ? manager.getSession() : undefined)\n useEffect(() => {\n return manager?.onChange(setSession)\n }, [])\n return session\n}\n"],"names":["sessionKey","AuthManager","useState","useEffect"],"mappings":";;;;;AAAa,MAAA,YAAA,GAAe,IAAI,MAAA,CAAO,6CAA6C,CAAA;;ACApF,IAAA,EAAA,CAAA;AAGA,MAAM,SAAY,GAAA,IAAI,GAAI,CAAA,QAAA,CAAS,IAAI,CAAA,CAAA;AACvC,MAAM,gBAAe,EAAa,GAAA,YAAA,CAAA,IAAA,CAAK,SAAU,CAAA,IAAI,MAAhC,IAAoC,GAAA,KAAA,CAAA,GAAA,EAAA,CAAA,CAAA,CAAA,CAAA;AACzD,MAAM,uBAAA,GAA0B,UAAU,YAAY,CAAA,kBAAA,CAAA,CAAA;AACtD,MAAMA,YAAA,GAAa,cAAc,YAAY,CAAA,CAAA,CAAA;AAE7C,MAAM,SAAA,GAAY,CAAC,GAAA,EAAa,KAAkB,KAAA;AAChD,EAAA,QAAA,CAAS,SAAS,CAAG,EAAA,GAAG,CAAI,CAAA,EAAA,KAAK,KAAK,uBAAuB,CAAA,CAAA,CAAA;AAC/D,CAAA,CAAA;AAEA,MAAM,YAAA,GAAe,CAAC,GAAgB,KAAA;AACpC,EAAA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GAAO,MAAM,QAAA,CAAS,IAAK,EAAA,CAAA;AAEjC,IAAI,IAAA,CAAC,SAAS,EAAI,EAAA;AAEhB,MAAQ,OAAA,CAAA,KAAA,CAAM,2CAA2C,IAAI,CAAA,CAAA;AAAA,KAC/D;AAAA,GACF;AACF,CAAA,CAAA;AA7KE,aAAA,CALW,eAKJ,EAAA,UAAA,CAAA,CAAA;AALF,IAAM,cAAN,GAAA;;ACnBA,SAAS,UAAa,GAAA;AAC3B,EAAA,MAAM,UAAU,cAAe,CAAA,QAAA,CAAA;AAC/B,EAAM,MAAA,CAAC,OAAS,EAAA,UAAU,CAAI,GAAAC,cAAA,CAAA,CAA8B,mCAAS,UAAe,EAAA,IAAA,OAAA,CAAQ,UAAW,EAAA,GAAI,KAAS,CAAA,CAAA,CAAA;AACpH,EAAAC,eAAA,CAAU,MAAM;AACd,IAAA,OAAO,mCAAS,QAAS,CAAA,UAAA,CAAA,CAAA;AAAA,GAC3B,EAAG,EAAE,CAAA,CAAA;AACL,EAAO,OAAA,OAAA,CAAA;AACT;;;;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/Login.tsx","../src/utils/cookies.ts","../src/utils/redirect.ts","../src/SessionManager.ts","../src/Authenticated.tsx","../src/hooks.ts"],"sourcesContent":["/* eslint-disable max-len */\nimport { Button, IconBox, Input, Text } from '@citric/core'\nimport { Github } from '@citric/icons'\nimport { LoadingCircular } from '@citric/ui'\nimport { BannerWarning } from '@stack-spot/portal-components'\nimport { MiniLogo } from '@stack-spot/portal-components/svg'\nimport { theme } from '@stack-spot/portal-theme'\nimport { Dictionary, useTranslate } from '@stack-spot/portal-translate'\nimport { useState } from 'react'\nimport { styled } from 'styled-components'\n\nexport type LoginType = 'sso' | 'idp'\n\ninterface BaseData {\n type: LoginType,\n}\n\ninterface SSOData extends BaseData {\n type: 'sso',\n email: string,\n}\n\ninterface IDPData extends BaseData {\n type: 'idp',\n provider: 'external-idp:github',\n}\n\ntype LoginData = SSOData | IDPData\n\nexport type LoginProps = {\n initialValue?: string,\n onSubmit: (data: LoginData) => Promise<void>,\n welcomeText?: string,\n removeLoadingOnSuccess?: boolean,\n className?: string,\n style?: React.CSSProperties,\n banner?: React.ReactNode,\n loginTypes?: LoginType[]\n}\n\nconst LoginBox = styled.form`\n display: flex;\n flex-direction: column;\n justify-content: center;\n gap: 24px;\n\n header {\n display: flex;\n flex-direction: column;\n align-items: center;\n gap: 24px;\n }\n\n .title {\n font-size: 1rem;\n }\n\n .separator {\n padding: 0 8px;\n background-color: ${theme.color.light['400']};\n color: ${theme.color.light['700']};\n display: flex;\n flex-direction: row;\n align-items: center;\n justify-content: center;\n gap: 20px;\n margin: 0;\n\n &:before, &:after {\n content: '';\n height: 1px;\n flex: 1;\n background-color: ${theme.color.light['600']};\n }\n }\n\n .error {\n color: ${theme.color.danger['500']};\n line-height: 1.5rem;\n }\n`\n\nexport const Login = ({ onSubmit, initialValue = '', welcomeText, removeLoadingOnSuccess, className, style, banner, loginTypes = ['idp', 'sso'] }: LoginProps) => {\n const t = useTranslate(dictionary)\n const searchParams = new URLSearchParams(location.search)\n const [error, setError] = useState(searchParams.get('error_description') || searchParams.get('error') || '')\n const [loading, setLoading] = useState(false)\n const [email, setEmail] = useState(initialValue)\n const disabled = !email.match(/\\w+@\\w+/)\n const idpLoginEnabled = loginTypes.includes('idp')\n const ssoLoginEnabled = loginTypes.includes('sso')\n\n async function login(type: LoginType) {\n setError('')\n setLoading(true)\n try {\n const data: LoginData = type === 'sso' ? { type: 'sso', email } : { type: 'idp', provider: 'external-idp:github' }\n await onSubmit(data)\n if (removeLoadingOnSuccess) setLoading(false)\n } catch (error: any) {\n setLoading(false)\n setError(error.message || error.toString())\n }\n }\n\n function submitForm(e: React.FormEvent<HTMLFormElement>) {\n e.preventDefault()\n if (disabled) return\n login('sso')\n }\n\n return (\n <>\n <LoginBox onSubmit={submitForm} className={className} style={style}>\n <header>\n <MiniLogo />\n <Text className=\"title\">{welcomeText || t.welcome}</Text>\n </header>\n {ssoLoginEnabled && <>\n <Input name=\"email\" value={email} onChange={e => setEmail(e.target.value)} placeholder={t.placeholder} />\n <Button colorScheme=\"primary\" disabled={disabled || loading}>\n {loading ? <LoadingCircular /> : <Text>{t.continue}</Text>}\n </Button>\n </>}\n {ssoLoginEnabled && idpLoginEnabled && <p className=\"separator\">{t.or}</p>}\n {idpLoginEnabled &&\n <Button colorScheme=\"light\" type=\"button\" onClick={() => login('idp')} disabled={loading}>\n {loading ? <LoadingCircular /> : (\n <>\n <IconBox>\n <Github />\n </IconBox>\n <Text>{t.loginWithGithub}</Text>\n </>\n )}\n </Button>}\n {error && <Text className=\"error\">{t.error}: {error}</Text>}\n </LoginBox>\n {banner ? <BannerWarning>\n {banner}\n </BannerWarning> : null}\n </>\n )\n}\n\nconst dictionary = {\n en: {\n welcome: 'Welcome to StackSpot',\n placeholder: 'your@email.com',\n continue: 'Continue',\n or: 'or',\n loginWithGithub: 'Login with Github',\n error: 'Error while attempting to login',\n },\n pt: {\n welcome: 'Bem vindo à StackSpot',\n placeholder: 'nome@email.com',\n continue: 'Continuar',\n or: 'ou',\n loginWithGithub: 'Logar com o GitHub',\n error: 'Erro ao fazer login',\n },\n} satisfies Dictionary\n","import { ThirdPartyLoginParams } from '@stack-spot/auth'\nimport { getCookie, getCookieDomain, removeCookie, setCookie } from '@stack-spot/portal-components'\n\nconst sessionKey = `stk-session${getCookieDomain()}`\n\ntype SessionCookie = ThirdPartyLoginParams & { sub: string }\n\nexport const sessionCookie = Object.freeze({\n set: (data: SessionCookie) => setCookie(sessionKey, JSON.stringify(data)),\n get: (): SessionCookie | undefined => {\n try {\n const cookie = getCookie(sessionKey)\n return cookie ? JSON.parse(cookie) : undefined\n } catch (error) {\n console.error(error)\n }\n },\n delete: () => removeCookie(sessionKey)\n})\n","export const redirect = async (url: string) => {\n window.location.href = url\n /**\n * This is intentional. The promise bellow will never be fulfilled.\n * Once the set href is not instantaneous, this will guarantee no further code is executed until the user is really redirected.\n * Particularly useful to prevent flickering page renders on scenarios with redirects.\n */\n await new Promise(() => '')\n}","import { AuthConfig, AuthManager, Session, ThirdPartyAuthType, ThirdPartyLoginParams } from '@stack-spot/auth'\nimport { sessionCookie } from './utils/cookies'\nimport { redirect } from './utils/redirect'\n\nconst sessionKey = 'session'\n\ninterface SessionManagerConfig extends Pick<AuthConfig, 'accountUrl' | 'authUrl' | 'clientId' | 'defaultTenant' | 'redirectUrl'> {\n loginUrl: string,\n blockedAuthTypes?: ThirdPartyAuthType[]\n rdUrl?: string,\n}\n\ntype AuthExtraData = { from?: string | null, finalRedirect?: string | null }\n\ntype ChangeListener = (session: Session | undefined) => void\n\n/**\n * Controls the current session in a browser.\n * \n * This should not be used under a Node.JS environment.\n * \n * This is a singleton. To create the first instance or recover the current one, use `SessionManager.create`.\n */\nexport class SessionManager {\n private current: Session | undefined\n private readonly auth: AuthManager<AuthExtraData>\n private config: SessionManagerConfig\n private changeListeners: ChangeListener[] = []\n static instance: SessionManager\n\n private constructor(config: SessionManagerConfig) {\n this.config = config\n this.auth = new AuthManager<AuthExtraData>({\n ...config,\n storage: localStorage,\n sessionPersistence: {\n load: () => localStorage.getItem(sessionKey),\n save: (session) => localStorage.setItem(sessionKey, session),\n },\n })\n SessionManager.instance = this\n\n // Keep session in sync with other app's session\n addEventListener('focus', () => this.validateSharedSession())\n }\n\n static create(config: SessionManagerConfig) {\n return SessionManager.instance ?? new SessionManager(config)\n }\n\n private setSession(session: Session | undefined) {\n this.current = session\n this.changeListeners.forEach(l => l(session))\n if (session) this.setSessionCookie(session)\n }\n\n async restoreSession() {\n const session = await this.auth.restoreSession()\n const sessionValid = await this.validateSharedSession(session)\n this.setSession(sessionValid ? session : undefined)\n }\n\n async validateSharedSession(session: Session | undefined = this.current): Promise<boolean> {\n\n // skipping because authentication is in progress\n if (this.urlHasThirdPartyLoginData()) return false\n\n const sharedSessionCookie = sessionCookie.get()\n\n // It has been logged out on another portal, so logout on this one too\n if (!sharedSessionCookie) {\n session && await this.logout()\n return false\n }\n\n const isDifferentSessionActive = sharedSessionCookie.sub != session?.getTokenData().sub\n const isSharedSessionTypeBlocked = this.config.blockedAuthTypes?.includes(sharedSessionCookie.type)\n if (isSharedSessionTypeBlocked) return false\n else if (isDifferentSessionActive || !session) {\n await this.startThirdPartyLogin(sharedSessionCookie)\n return false\n }\n return true\n }\n\n hasSession() {\n return !!this.current && !this.current.isExpired()\n }\n\n getSession() {\n if (!this.hasSession()) {\n this.endSession()\n throw new Error('Session is not available, redirecting to login.')\n }\n return this.current!\n }\n\n async endSession(redirectToLogin = true) {\n this.current = undefined\n localStorage.removeItem(sessionKey)\n sessionCookie.delete()\n if (redirectToLogin) await redirect(this.config.loginUrl)\n }\n\n async logout() {\n try {\n await this.current?.logout()\n } catch (error) {\n // eslint-disable-next-line no-console\n console.error(`Could not logout from IDM.\\n${error}`)\n }\n await this.endSession()\n }\n\n async startThirdPartyLogin(data: ThirdPartyLoginParams) {\n const params = new URLSearchParams(location.search)\n const authUrl = await this.auth.startThirdPartyLogin(data, {\n from: location.href,\n finalRedirect: params.get('finalRedirect'),\n })\n await redirect(authUrl)\n }\n\n urlHasThirdPartyLoginData() {\n const url = new URL(location.toString())\n return url.searchParams.has('state') && !url.searchParams.has('error')\n }\n\n async completeThirdPartyLogin() {\n const url = new URL(location.toString())\n if (url.searchParams.has('error')) {\n throw new Error(`Error while signing in: ${url.searchParams.get('error_description')}`)\n }\n const { session, data: { from, finalRedirect } } = await this.auth.completeThirdPartyLogin(location.search)\n this.setSession(session)\n history.replaceState(null, '', from || location.toString().replace(/\\?.*$/, ''))\n this.sendLoginEventRd(this.current?.getTokenData().email, this.current?.getTokenData().name)\n if (finalRedirect) await redirect(finalRedirect)\n }\n\n getEmailForLogin() {\n const session = sessionCookie.get()\n return session?.type == 'sso' ? session.email : undefined\n }\n\n async switchAccount(accountId: string) {\n this.current && await this.auth.switchAccount(accountId, this.current)\n this.setSession(this.current)\n }\n\n onChange(listener: ChangeListener) {\n this.changeListeners.push(listener)\n return () => {\n const index = this.changeListeners.indexOf(listener)\n if (index != -1) this.changeListeners.splice(index, 1)\n }\n }\n\n private setSessionCookie(session: Session) {\n const { email, account_type, sub } = session.getTokenData()\n if (!email || !sub) return\n const isFreemium = account_type == 'FREEMIUM'\n if (isFreemium) {\n sessionCookie.set({ type: 'idp', provider: 'external-idp:github', sub })\n } else {\n sessionCookie.set({ email, type: 'sso', sub })\n }\n }\n\n private async sendLoginEventRd(email?: string, name?: string) {\n if (!this.config.rdUrl) return\n if (!email && !name) {\n // eslint-disable-next-line no-console\n console.error('Unable to trigger login hook. No sessionEmail or name identified.')\n return\n }\n\n const rdObject = {\n event_type: 'CONVERSION',\n event_family: 'CDP',\n payload: {\n email,\n name,\n conversion_identifier: 'login-v1',\n },\n }\n\n const response = await fetch(this.config.rdUrl, {\n method: 'POST',\n body: JSON.stringify(rdObject),\n headers: {\n 'content-type': 'application/json',\n },\n })\n const data = await response.json()\n\n if (!response.ok) {\n // eslint-disable-next-line no-console\n console.error('Error while sending event to RD Station', data)\n }\n }\n}\n","/* eslint-disable max-len */\nimport { Flex } from '@citric/core'\nimport { useEffectOnce } from '@stack-spot/portal-components'\nimport { CSSToCitricAdapter } from '@stack-spot/portal-theme'\nimport '@stack-spot/portal-theme/dist/theme.css'\nimport { useLanguage } from '@stack-spot/portal-translate'\nimport { useState } from 'react'\nimport { Login, LoginProps } from './Login'\nimport { SessionManager } from './SessionManager'\n\ntype AuthStatus = 'unknown' | 'authenticated' | 'unauthenticated'\n\ninterface Props {\n children: React.ReactElement\n onLogin?: () => void\n onSession?: () => void\n customLoginProps?: Omit<LoginProps, 'onSubmit' | 'initialValue'>\n}\n\nexport const Authenticated = ({ children, onLogin, onSession, customLoginProps }: Props) => {\n const [authStatus, setAuthStatus] = useState<AuthStatus>('unknown')\n const language = useLanguage()\n const sessionManager = SessionManager.instance\n\n useEffectOnce(() => {\n async function checkAuth() {\n await sessionManager.restoreSession()\n if (sessionManager.urlHasThirdPartyLoginData()) {\n await sessionManager.completeThirdPartyLogin()\n onLogin?.()\n }\n if (sessionManager.hasSession()) {\n setAuthStatus('authenticated')\n onSession?.()\n } else {\n setAuthStatus('unauthenticated')\n }\n }\n\n checkAuth()\n })\n\n if (authStatus === 'unknown') return null\n if (authStatus === 'authenticated') return children\n\n return (\n <CSSToCitricAdapter>\n <Flex justifyContent=\"center\" alignItems=\"center\" flex={1} style={{ height: '100%' }}>\n <Login\n style={{ width: '360px' }}\n onSubmit={data => sessionManager.startThirdPartyLogin({ ...data, locale: language })}\n initialValue={sessionManager.getEmailForLogin()}\n {...(customLoginProps || {})}\n />\n </Flex>\n </CSSToCitricAdapter>\n )\n}\n","import { Session } from '@stack-spot/auth'\nimport { useEffect, useState } from 'react'\nimport { SessionManager } from './SessionManager'\n\nexport function useSession() {\n const manager = SessionManager.instance\n const [session, setSession] = useState<Session | undefined>(manager?.hasSession() ? manager.getSession() : undefined)\n useEffect(() => {\n return manager?.onChange(setSession)\n }, [])\n return session\n}\n"],"names":["styled","theme","useTranslate","useState","error","jsxs","Fragment","jsx","MiniLogo","Text","Input","Button","LoadingCircular","IconBox","Github","BannerWarning","sessionKey","getCookieDomain","setCookie","getCookie","removeCookie","AuthManager","__spreadProps","__spreadValues","useLanguage","useEffectOnce","CSSToCitricAdapter","Flex","useEffect"],"mappings":";;;;;;;;;;;;;;;AAwCA,MAAM,WAAWA,uBAAO,CAAA,IAAA,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAAA,EAmBAC,iBAAM,CAAA,KAAA,CAAM,KAAM,CAAA,KAAK,CAAC,CAAA;AAAA,WAAA,EACnCA,iBAAM,CAAA,KAAA,CAAM,KAAM,CAAA,KAAK,CAAC,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAAA,EAYXA,iBAAM,CAA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,EAAA,uBACGlB,cAAA,CAAAmB,8BAAA,EAAA,EACC,QAAC,kBAAAnB,cAAA,CAAAoB,SAAA,EAAA,EAAK,gBAAe,QAAS,EAAA,UAAA,EAAW,QAAS,EAAA,IAAA,EAAM,CAAG,EAAA,KAAA,EAAO,EAAE,MAAA,EAAQ,QAC1E,EAAA,QAAA,kBAAApB,cAAA;AAAA,IAAC,KAAA;AAAA,IAAA,cAAA,CAAA;AAAA,MACC,KAAA,EAAO,EAAE,KAAA,EAAO,OAAQ,EAAA;AAAA,MACxB,QAAA,EAAU,UAAQ,cAAe,CAAA,oBAAA,CAAqB,iCAAK,IAAL,CAAA,EAAA,EAAW,MAAQ,EAAA,QAAA,EAAU,CAAA,CAAA;AAAA,MACnF,YAAA,EAAc,eAAe,gBAAiB,EAAA;AAAA,KAAA,EACzC,oBAAoB,EAAC,CAAA;AAAA,KAE9B,CACF,EAAA,CAAA,CAAA;AAEJ;;ACrDO,SAAS,UAAa,GAAA;AAC3B,EAAA,MAAM,UAAU,cAAe,CAAA,QAAA,CAAA;AAC/B,EAAM,MAAA,CAAC,OAAS,EAAA,UAAU,CAAI,GAAAJ,cAAA,CAAA,CAA8B,mCAAS,UAAe,EAAA,IAAA,OAAA,CAAQ,UAAW,EAAA,GAAI,KAAS,CAAA,CAAA,CAAA;AACpH,EAAAyB,eAAA,CAAU,MAAM;AACd,IAAA,OAAO,mCAAS,QAAS,CAAA,UAAA,CAAA,CAAA;AAAA,GAC3B,EAAG,EAAE,CAAA,CAAA;AACL,EAAO,OAAA,OAAA,CAAA;AACT;;;;;;;"}
|
package/out/index.mjs
CHANGED
|
@@ -1,25 +1,129 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { Text, Input, Button, IconBox, Flex } from '@citric/core';
|
|
3
|
+
import { BannerWarning, getCookieDomain, setCookie, getCookie, removeCookie, useEffectOnce } from '@stack-spot/portal-components';
|
|
4
|
+
import { theme, CSSToCitricAdapter } from '@stack-spot/portal-theme';
|
|
5
|
+
import '@stack-spot/portal-theme/dist/theme.css';
|
|
6
|
+
import { useTranslate, useLanguage } from '@stack-spot/portal-translate';
|
|
2
7
|
import { useState, useEffect } from 'react';
|
|
8
|
+
import { Github } from '@citric/icons';
|
|
9
|
+
import { LoadingCircular } from '@citric/ui';
|
|
10
|
+
import { MiniLogo } from '@stack-spot/portal-components/svg';
|
|
11
|
+
import { styled } from 'styled-components';
|
|
12
|
+
import { AuthManager } from '@stack-spot/auth';
|
|
13
|
+
|
|
14
|
+
const LoginBox = styled.form`
|
|
15
|
+
display: flex;
|
|
16
|
+
flex-direction: column;
|
|
17
|
+
justify-content: center;
|
|
18
|
+
gap: 24px;
|
|
19
|
+
|
|
20
|
+
header {
|
|
21
|
+
display: flex;
|
|
22
|
+
flex-direction: column;
|
|
23
|
+
align-items: center;
|
|
24
|
+
gap: 24px;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.title {
|
|
28
|
+
font-size: 1rem;
|
|
29
|
+
}
|
|
3
30
|
|
|
4
|
-
|
|
31
|
+
.separator {
|
|
32
|
+
padding: 0 8px;
|
|
33
|
+
background-color: ${theme.color.light["400"]};
|
|
34
|
+
color: ${theme.color.light["700"]};
|
|
35
|
+
display: flex;
|
|
36
|
+
flex-direction: row;
|
|
37
|
+
align-items: center;
|
|
38
|
+
justify-content: center;
|
|
39
|
+
gap: 20px;
|
|
40
|
+
margin: 0;
|
|
5
41
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
42
|
+
&:before, &:after {
|
|
43
|
+
content: '';
|
|
44
|
+
height: 1px;
|
|
45
|
+
flex: 1;
|
|
46
|
+
background-color: ${theme.color.light["600"]};
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.error {
|
|
51
|
+
color: ${theme.color.danger["500"]};
|
|
52
|
+
line-height: 1.5rem;
|
|
53
|
+
}
|
|
54
|
+
`;
|
|
55
|
+
const Login = ({ onSubmit, initialValue = "", welcomeText, removeLoadingOnSuccess, className, style, banner, loginTypes = ["idp", "sso"] }) => {
|
|
56
|
+
const t = useTranslate(dictionary);
|
|
57
|
+
const searchParams = new URLSearchParams(location.search);
|
|
58
|
+
const [error, setError] = useState(searchParams.get("error_description") || searchParams.get("error") || "");
|
|
59
|
+
const [loading, setLoading] = useState(false);
|
|
60
|
+
const [email, setEmail] = useState(initialValue);
|
|
61
|
+
const disabled = !email.match(/\w+@\w+/);
|
|
62
|
+
const idpLoginEnabled = loginTypes.includes("idp");
|
|
63
|
+
const ssoLoginEnabled = loginTypes.includes("sso");
|
|
64
|
+
async function login(type) {
|
|
65
|
+
setError("");
|
|
66
|
+
setLoading(true);
|
|
67
|
+
try {
|
|
68
|
+
const data = type === "sso" ? { type: "sso", email } : { type: "idp", provider: "external-idp:github" };
|
|
69
|
+
await onSubmit(data);
|
|
70
|
+
if (removeLoadingOnSuccess)
|
|
71
|
+
setLoading(false);
|
|
72
|
+
} catch (error2) {
|
|
73
|
+
setLoading(false);
|
|
74
|
+
setError(error2.message || error2.toString());
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
function submitForm(e) {
|
|
78
|
+
e.preventDefault();
|
|
79
|
+
if (disabled)
|
|
80
|
+
return;
|
|
81
|
+
login("sso");
|
|
82
|
+
}
|
|
83
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
84
|
+
/* @__PURE__ */ jsxs(LoginBox, { onSubmit: submitForm, className, style, children: [
|
|
85
|
+
/* @__PURE__ */ jsxs("header", { children: [
|
|
86
|
+
/* @__PURE__ */ jsx(MiniLogo, {}),
|
|
87
|
+
/* @__PURE__ */ jsx(Text, { className: "title", children: welcomeText || t.welcome })
|
|
88
|
+
] }),
|
|
89
|
+
ssoLoginEnabled && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
90
|
+
/* @__PURE__ */ jsx(Input, { name: "email", value: email, onChange: (e) => setEmail(e.target.value), placeholder: t.placeholder }),
|
|
91
|
+
/* @__PURE__ */ jsx(Button, { colorScheme: "primary", disabled: disabled || loading, children: loading ? /* @__PURE__ */ jsx(LoadingCircular, {}) : /* @__PURE__ */ jsx(Text, { children: t.continue }) })
|
|
92
|
+
] }),
|
|
93
|
+
ssoLoginEnabled && idpLoginEnabled && /* @__PURE__ */ jsx("p", { className: "separator", children: t.or }),
|
|
94
|
+
idpLoginEnabled && /* @__PURE__ */ jsx(Button, { colorScheme: "light", type: "button", onClick: () => login("idp"), disabled: loading, children: loading ? /* @__PURE__ */ jsx(LoadingCircular, {}) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
95
|
+
/* @__PURE__ */ jsx(IconBox, { children: /* @__PURE__ */ jsx(Github, {}) }),
|
|
96
|
+
/* @__PURE__ */ jsx(Text, { children: t.loginWithGithub })
|
|
97
|
+
] }) }),
|
|
98
|
+
error && /* @__PURE__ */ jsxs(Text, { className: "error", children: [
|
|
99
|
+
t.error,
|
|
100
|
+
": ",
|
|
101
|
+
error
|
|
102
|
+
] })
|
|
103
|
+
] }),
|
|
104
|
+
banner ? /* @__PURE__ */ jsx(BannerWarning, { children: banner }) : null
|
|
105
|
+
] });
|
|
13
106
|
};
|
|
14
|
-
const
|
|
15
|
-
|
|
107
|
+
const dictionary = {
|
|
108
|
+
en: {
|
|
109
|
+
welcome: "Welcome to StackSpot",
|
|
110
|
+
placeholder: "your@email.com",
|
|
111
|
+
continue: "Continue",
|
|
112
|
+
or: "or",
|
|
113
|
+
loginWithGithub: "Login with Github",
|
|
114
|
+
error: "Error while attempting to login"
|
|
115
|
+
},
|
|
116
|
+
pt: {
|
|
117
|
+
welcome: "Bem vindo \xE0 StackSpot",
|
|
118
|
+
placeholder: "nome@email.com",
|
|
119
|
+
continue: "Continuar",
|
|
120
|
+
or: "ou",
|
|
121
|
+
loginWithGithub: "Logar com o GitHub",
|
|
122
|
+
error: "Erro ao fazer login"
|
|
123
|
+
}
|
|
16
124
|
};
|
|
17
|
-
|
|
18
|
-
const
|
|
19
|
-
const [name, ...value] = current.split("=");
|
|
20
|
-
prev[name] = value.join("=");
|
|
21
|
-
return prev;
|
|
22
|
-
}, {});
|
|
125
|
+
|
|
126
|
+
const sessionKey$1 = `stk-session${getCookieDomain()}`;
|
|
23
127
|
const sessionCookie = Object.freeze({
|
|
24
128
|
set: (data) => setCookie(sessionKey$1, JSON.stringify(data)),
|
|
25
129
|
get: () => {
|
|
@@ -38,27 +142,27 @@ const redirect = async (url) => {
|
|
|
38
142
|
await new Promise(() => "");
|
|
39
143
|
};
|
|
40
144
|
|
|
41
|
-
var __defProp = Object.defineProperty;
|
|
42
|
-
var __defProps = Object.defineProperties;
|
|
43
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
44
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
45
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
46
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
47
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
48
|
-
var __spreadValues = (a, b) => {
|
|
145
|
+
var __defProp$1 = Object.defineProperty;
|
|
146
|
+
var __defProps$1 = Object.defineProperties;
|
|
147
|
+
var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
|
|
148
|
+
var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
|
|
149
|
+
var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
|
|
150
|
+
var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
|
|
151
|
+
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
152
|
+
var __spreadValues$1 = (a, b) => {
|
|
49
153
|
for (var prop in b || (b = {}))
|
|
50
|
-
if (__hasOwnProp.call(b, prop))
|
|
51
|
-
__defNormalProp(a, prop, b[prop]);
|
|
52
|
-
if (__getOwnPropSymbols)
|
|
53
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
54
|
-
if (__propIsEnum.call(b, prop))
|
|
55
|
-
__defNormalProp(a, prop, b[prop]);
|
|
154
|
+
if (__hasOwnProp$1.call(b, prop))
|
|
155
|
+
__defNormalProp$1(a, prop, b[prop]);
|
|
156
|
+
if (__getOwnPropSymbols$1)
|
|
157
|
+
for (var prop of __getOwnPropSymbols$1(b)) {
|
|
158
|
+
if (__propIsEnum$1.call(b, prop))
|
|
159
|
+
__defNormalProp$1(a, prop, b[prop]);
|
|
56
160
|
}
|
|
57
161
|
return a;
|
|
58
162
|
};
|
|
59
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
163
|
+
var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
|
|
60
164
|
var __publicField = (obj, key, value) => {
|
|
61
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
165
|
+
__defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
62
166
|
return value;
|
|
63
167
|
};
|
|
64
168
|
const sessionKey = "session";
|
|
@@ -69,7 +173,7 @@ const _SessionManager = class _SessionManager {
|
|
|
69
173
|
__publicField(this, "config");
|
|
70
174
|
__publicField(this, "changeListeners", []);
|
|
71
175
|
this.config = config;
|
|
72
|
-
this.auth = new AuthManager(__spreadProps(__spreadValues({}, config), {
|
|
176
|
+
this.auth = new AuthManager(__spreadProps$1(__spreadValues$1({}, config), {
|
|
73
177
|
storage: localStorage,
|
|
74
178
|
sessionPersistence: {
|
|
75
179
|
load: () => localStorage.getItem(sessionKey),
|
|
@@ -224,6 +328,59 @@ ${error}`);
|
|
|
224
328
|
__publicField(_SessionManager, "instance");
|
|
225
329
|
let SessionManager = _SessionManager;
|
|
226
330
|
|
|
331
|
+
var __defProp = Object.defineProperty;
|
|
332
|
+
var __defProps = Object.defineProperties;
|
|
333
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
334
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
335
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
336
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
337
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
338
|
+
var __spreadValues = (a, b) => {
|
|
339
|
+
for (var prop in b || (b = {}))
|
|
340
|
+
if (__hasOwnProp.call(b, prop))
|
|
341
|
+
__defNormalProp(a, prop, b[prop]);
|
|
342
|
+
if (__getOwnPropSymbols)
|
|
343
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
344
|
+
if (__propIsEnum.call(b, prop))
|
|
345
|
+
__defNormalProp(a, prop, b[prop]);
|
|
346
|
+
}
|
|
347
|
+
return a;
|
|
348
|
+
};
|
|
349
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
350
|
+
const Authenticated = ({ children, onLogin, onSession, customLoginProps }) => {
|
|
351
|
+
const [authStatus, setAuthStatus] = useState("unknown");
|
|
352
|
+
const language = useLanguage();
|
|
353
|
+
const sessionManager = SessionManager.instance;
|
|
354
|
+
useEffectOnce(() => {
|
|
355
|
+
async function checkAuth() {
|
|
356
|
+
await sessionManager.restoreSession();
|
|
357
|
+
if (sessionManager.urlHasThirdPartyLoginData()) {
|
|
358
|
+
await sessionManager.completeThirdPartyLogin();
|
|
359
|
+
onLogin == null ? void 0 : onLogin();
|
|
360
|
+
}
|
|
361
|
+
if (sessionManager.hasSession()) {
|
|
362
|
+
setAuthStatus("authenticated");
|
|
363
|
+
onSession == null ? void 0 : onSession();
|
|
364
|
+
} else {
|
|
365
|
+
setAuthStatus("unauthenticated");
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
checkAuth();
|
|
369
|
+
});
|
|
370
|
+
if (authStatus === "unknown")
|
|
371
|
+
return null;
|
|
372
|
+
if (authStatus === "authenticated")
|
|
373
|
+
return children;
|
|
374
|
+
return /* @__PURE__ */ jsx(CSSToCitricAdapter, { children: /* @__PURE__ */ jsx(Flex, { justifyContent: "center", alignItems: "center", flex: 1, style: { height: "100%" }, children: /* @__PURE__ */ jsx(
|
|
375
|
+
Login,
|
|
376
|
+
__spreadValues({
|
|
377
|
+
style: { width: "360px" },
|
|
378
|
+
onSubmit: (data) => sessionManager.startThirdPartyLogin(__spreadProps(__spreadValues({}, data), { locale: language })),
|
|
379
|
+
initialValue: sessionManager.getEmailForLogin()
|
|
380
|
+
}, customLoginProps || {})
|
|
381
|
+
) }) });
|
|
382
|
+
};
|
|
383
|
+
|
|
227
384
|
function useSession() {
|
|
228
385
|
const manager = SessionManager.instance;
|
|
229
386
|
const [session, setSession] = useState((manager == null ? void 0 : manager.hasSession()) ? manager.getSession() : void 0);
|
|
@@ -233,5 +390,5 @@ function useSession() {
|
|
|
233
390
|
return session;
|
|
234
391
|
}
|
|
235
392
|
|
|
236
|
-
export { SessionManager, useSession };
|
|
393
|
+
export { Authenticated, Login, SessionManager, useSession };
|
|
237
394
|
//# sourceMappingURL=index.mjs.map
|
package/out/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../src/utils/regex.ts","../src/utils/cookies.ts","../src/utils/redirect.ts","../src/SessionManager.ts","../src/hooks.ts"],"sourcesContent":["export const DOMAIN_REGEX = new RegExp(/(\\.*(prd|stg|dev)*.stackspot.com)|localhost/)","import { ThirdPartyLoginParams } from \"@stack-spot/auth\"\nimport { DOMAIN_REGEX } from './regex'\n\nconst portalUrl = new URL(location.href)\nconst cookieDomain = DOMAIN_REGEX.exec(portalUrl.host)?.[0]\nconst defaultCookieAttributes = `domain=${cookieDomain}; SameSite=Strict;`\nconst sessionKey = `stk-session${cookieDomain}`\n\nconst setCookie = (key: string, value: string) => {\n document.cookie = `${key}=${value}; ${defaultCookieAttributes}`\n}\n\nconst removeCookie = (key: string) => {\n document.cookie = `${key}=; max-age=0; ${defaultCookieAttributes}`\n}\n\nconst getCookie = (key: string) => getCookies()[key]\n\nconst getCookies = (): Record<string, string> => document.cookie.split('; ').reduce((prev, current) => {\n const [name, ...value] = current.split('=')\n prev[name] = value.join('=')\n return prev\n}, {} as Record<string, string>)\n\n\ntype SessionCookie = ThirdPartyLoginParams & { sub: string }\nexport const sessionCookie = Object.freeze({\n set: (data: SessionCookie) => setCookie(sessionKey, JSON.stringify(data)),\n get: (): SessionCookie | undefined => {\n try {\n const cookie = getCookie(sessionKey)\n return cookie ? JSON.parse(cookie) : undefined\n } catch (error) {\n console.error(error)\n }\n },\n delete: () => removeCookie(sessionKey)\n})","\n\nexport const redirect = async (url: string) => {\n window.location.href = url\n /**\n * This is intentional. The promise bellow will never be fulfilled.\n * Once the set href is not instantaneous, this will guarantee no further code is executed until the user is really redirected.\n * Particularly useful to prevent flickering page renders on scenarios with redirects.\n */\n await new Promise(() => '')\n}","import { AuthConfig, AuthManager, Session, ThirdPartyAuthType, ThirdPartyLoginParams } from '@stack-spot/auth'\nimport { sessionCookie } from './utils/cookies'\nimport { redirect } from './utils/redirect'\n\nconst sessionKey = 'session'\n\ninterface SessionManagerConfig extends Pick<AuthConfig, 'accountUrl' | 'authUrl' | 'clientId' | 'defaultTenant' | 'redirectUrl'> {\n loginUrl: string,\n blockedAuthTypes?: ThirdPartyAuthType[]\n rdUrl?: string,\n}\n\ntype AuthExtraData = { from?: string | null, finalRedirect?: string | null }\n\ntype ChangeListener = (session: Session | undefined) => void\n\n/**\n * Controls the current session in a browser.\n * \n * This should not be used under a Node.JS environment.\n * \n * This is a singleton. To create the first instance or recover the current one, use `SessionManager.create`.\n */\nexport class SessionManager {\n private current: Session | undefined\n private readonly auth: AuthManager<AuthExtraData>\n private config: SessionManagerConfig\n private changeListeners: ChangeListener[] = []\n static instance: SessionManager\n\n private constructor(config: SessionManagerConfig) {\n this.config = config\n this.auth = new AuthManager<AuthExtraData>({\n ...config,\n storage: localStorage,\n sessionPersistence: {\n load: () => localStorage.getItem(sessionKey),\n save: (session) => localStorage.setItem(sessionKey, session),\n },\n })\n SessionManager.instance = this\n\n // Keep session in sync with other app's session\n addEventListener('focus', () => this.validateSharedSession())\n }\n\n static create(config: SessionManagerConfig) {\n return SessionManager.instance ?? new SessionManager(config)\n }\n\n private setSession(session: Session | undefined) {\n this.current = session\n this.changeListeners.forEach(l => l(session))\n if (session) this.setSessionCookie(session)\n }\n\n async restoreSession() {\n const session = await this.auth.restoreSession()\n const sessionValid = await this.validateSharedSession(session)\n this.setSession(sessionValid ? session : undefined)\n }\n\n async validateSharedSession(session: Session | undefined = this.current): Promise<boolean> {\n\n // skipping because authentication is in progress\n if (this.urlHasThirdPartyLoginData()) return false\n\n const sharedSessionCookie = sessionCookie.get()\n\n // It has been logged out on another portal, so logout on this one too\n if (!sharedSessionCookie) {\n session && await this.logout()\n return false\n }\n\n const isDifferentSessionActive = sharedSessionCookie.sub != session?.getTokenData().sub\n const isSharedSessionTypeBlocked = this.config.blockedAuthTypes?.includes(sharedSessionCookie.type)\n if (isSharedSessionTypeBlocked) return false\n else if (isDifferentSessionActive || !session) {\n await this.startThirdPartyLogin(sharedSessionCookie)\n return false\n }\n return true\n }\n\n hasSession() {\n return !!this.current && !this.current.isExpired()\n }\n\n getSession() {\n if (!this.hasSession()) {\n this.endSession()\n throw new Error('Session is not available, redirecting to login.')\n }\n return this.current!\n }\n\n async endSession(redirectToLogin = true) {\n this.current = undefined\n localStorage.removeItem(sessionKey)\n sessionCookie.delete()\n if (redirectToLogin) await redirect(this.config.loginUrl)\n }\n\n async logout() {\n try {\n await this.current?.logout()\n } catch (error) {\n // eslint-disable-next-line no-console\n console.error(`Could not logout from IDM.\\n${error}`)\n }\n await this.endSession()\n }\n\n async startThirdPartyLogin(data: ThirdPartyLoginParams) {\n const params = new URLSearchParams(location.search)\n const authUrl = await this.auth.startThirdPartyLogin(data, {\n from: location.href,\n finalRedirect: params.get('finalRedirect'),\n })\n await redirect(authUrl)\n }\n\n urlHasThirdPartyLoginData() {\n const url = new URL(location.toString())\n return url.searchParams.has('state') && !url.searchParams.has('error')\n }\n\n async completeThirdPartyLogin() {\n const url = new URL(location.toString())\n if (url.searchParams.has('error')) {\n throw new Error(`Error while signing in: ${url.searchParams.get('error_description')}`)\n }\n const { session, data: { from, finalRedirect } } = await this.auth.completeThirdPartyLogin(location.search)\n this.setSession(session)\n history.replaceState(null, '', from || location.toString().replace(/\\?.*$/, ''))\n this.sendLoginEventRd(this.current?.getTokenData().email, this.current?.getTokenData().name)\n if (finalRedirect) await redirect(finalRedirect)\n }\n\n getEmailForLogin() {\n const session = sessionCookie.get()\n return session?.type == 'sso' ? session.email : undefined\n }\n\n async switchAccount(accountId: string) {\n this.current && await this.auth.switchAccount(accountId, this.current)\n this.setSession(this.current)\n }\n\n onChange(listener: ChangeListener) {\n this.changeListeners.push(listener)\n return () => {\n const index = this.changeListeners.indexOf(listener)\n if (index != -1) this.changeListeners.splice(index, 1)\n }\n }\n\n private setSessionCookie(session: Session) {\n const { email, account_type, sub } = session.getTokenData()\n if (!email || !sub) return\n const isFreemium = account_type == 'FREEMIUM'\n if (isFreemium) {\n sessionCookie.set({ type: 'idp', provider: 'external-idp:github', sub })\n } else {\n sessionCookie.set({ email, type: 'sso', sub })\n }\n }\n\n private async sendLoginEventRd(email?: string, name?: string) {\n if (!this.config.rdUrl) return\n if (!email && !name) {\n // eslint-disable-next-line no-console\n console.error('Unable to trigger login hook. No sessionEmail or name identified.')\n return\n }\n\n const rdObject = {\n event_type: 'CONVERSION',\n event_family: 'CDP',\n payload: {\n email,\n name,\n conversion_identifier: 'login-v1',\n },\n }\n\n const response = await fetch(this.config.rdUrl, {\n method: 'POST',\n body: JSON.stringify(rdObject),\n headers: {\n 'content-type': 'application/json',\n },\n })\n const data = await response.json()\n\n if (!response.ok) {\n // eslint-disable-next-line no-console\n console.error('Error while sending event to RD Station', data)\n }\n }\n}\n","import { Session } from '@stack-spot/auth'\nimport { useEffect, useState } from 'react'\nimport { SessionManager } from './SessionManager'\n\nexport function useSession() {\n const manager = SessionManager.instance\n const [session, setSession] = useState<Session | undefined>(manager?.hasSession() ? manager.getSession() : undefined)\n useEffect(() => {\n return manager?.onChange(setSession)\n }, [])\n return session\n}\n"],"names":["sessionKey"],"mappings":";;;AAAa,MAAA,YAAA,GAAe,IAAI,MAAA,CAAO,6CAA6C,CAAA;;ACApF,IAAA,EAAA,CAAA;AAGA,MAAM,SAAY,GAAA,IAAI,GAAI,CAAA,QAAA,CAAS,IAAI,CAAA,CAAA;AACvC,MAAM,gBAAe,EAAa,GAAA,YAAA,CAAA,IAAA,CAAK,SAAU,CAAA,IAAI,MAAhC,IAAoC,GAAA,KAAA,CAAA,GAAA,EAAA,CAAA,CAAA,CAAA,CAAA;AACzD,MAAM,uBAAA,GAA0B,UAAU,YAAY,CAAA,kBAAA,CAAA,CAAA;AACtD,MAAMA,YAAA,GAAa,cAAc,YAAY,CAAA,CAAA,CAAA;AAE7C,MAAM,SAAA,GAAY,CAAC,GAAA,EAAa,KAAkB,KAAA;AAChD,EAAA,QAAA,CAAS,SAAS,CAAG,EAAA,GAAG,CAAI,CAAA,EAAA,KAAK,KAAK,uBAAuB,CAAA,CAAA,CAAA;AAC/D,CAAA,CAAA;AAEA,MAAM,YAAA,GAAe,CAAC,GAAgB,KAAA;AACpC,EAAA,QAAA,CAAS,MAAS,GAAA,CAAA,EAAG,GAAG,CAAA,cAAA,EAAiB,uBAAuB,CAAA,CAAA,CAAA;AAClE,CAAA,CAAA;AAEA,MAAM,SAAY,GAAA,CAAC,GAAgB,KAAA,UAAA,GAAa,GAAG,CAAA,CAAA;AAEnD,MAAM,UAAA,GAAa,MAA8B,QAAA,CAAS,MAAO,CAAA,KAAA,CAAM,IAAI,CAAE,CAAA,MAAA,CAAO,CAAC,IAAA,EAAM,OAAY,KAAA;AACrG,EAAA,MAAM,CAAC,I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A;AAC/B,EAAM,MAAA,CAAC,OAAS,EAAA,UAAU,CAAI,GAAA,QAAA,CAAA,CAA8B,mCAAS,UAAe,EAAA,IAAA,OAAA,CAAQ,UAAW,EAAA,GAAI,KAAS,CAAA,CAAA,CAAA;AACpH,EAAA,SAAA,CAAU,MAAM;AACd,IAAA,OAAO,mCAAS,QAAS,CAAA,UAAA,CAAA,CAAA;AAAA,GAC3B,EAAG,EAAE,CAAA,CAAA;AACL,EAAO,OAAA,OAAA,CAAA;AACT;;;;"}
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../src/Login.tsx","../src/utils/cookies.ts","../src/utils/redirect.ts","../src/SessionManager.ts","../src/Authenticated.tsx","../src/hooks.ts"],"sourcesContent":["/* eslint-disable max-len */\nimport { Button, IconBox, Input, Text } from '@citric/core'\nimport { Github } from '@citric/icons'\nimport { LoadingCircular } from '@citric/ui'\nimport { BannerWarning } from '@stack-spot/portal-components'\nimport { MiniLogo } from '@stack-spot/portal-components/svg'\nimport { theme } from '@stack-spot/portal-theme'\nimport { Dictionary, useTranslate } from '@stack-spot/portal-translate'\nimport { useState } from 'react'\nimport { styled } from 'styled-components'\n\nexport type LoginType = 'sso' | 'idp'\n\ninterface BaseData {\n type: LoginType,\n}\n\ninterface SSOData extends BaseData {\n type: 'sso',\n email: string,\n}\n\ninterface IDPData extends BaseData {\n type: 'idp',\n provider: 'external-idp:github',\n}\n\ntype LoginData = SSOData | IDPData\n\nexport type LoginProps = {\n initialValue?: string,\n onSubmit: (data: LoginData) => Promise<void>,\n welcomeText?: string,\n removeLoadingOnSuccess?: boolean,\n className?: string,\n style?: React.CSSProperties,\n banner?: React.ReactNode,\n loginTypes?: LoginType[]\n}\n\nconst LoginBox = styled.form`\n display: flex;\n flex-direction: column;\n justify-content: center;\n gap: 24px;\n\n header {\n display: flex;\n flex-direction: column;\n align-items: center;\n gap: 24px;\n }\n\n .title {\n font-size: 1rem;\n }\n\n .separator {\n padding: 0 8px;\n background-color: ${theme.color.light['400']};\n color: ${theme.color.light['700']};\n display: flex;\n flex-direction: row;\n align-items: center;\n justify-content: center;\n gap: 20px;\n margin: 0;\n\n &:before, &:after {\n content: '';\n height: 1px;\n flex: 1;\n background-color: ${theme.color.light['600']};\n }\n }\n\n .error {\n color: ${theme.color.danger['500']};\n line-height: 1.5rem;\n }\n`\n\nexport const Login = ({ onSubmit, initialValue = '', welcomeText, removeLoadingOnSuccess, className, style, banner, loginTypes = ['idp', 'sso'] }: LoginProps) => {\n const t = useTranslate(dictionary)\n const searchParams = new URLSearchParams(location.search)\n const [error, setError] = useState(searchParams.get('error_description') || searchParams.get('error') || '')\n const [loading, setLoading] = useState(false)\n const [email, setEmail] = useState(initialValue)\n const disabled = !email.match(/\\w+@\\w+/)\n const idpLoginEnabled = loginTypes.includes('idp')\n const ssoLoginEnabled = loginTypes.includes('sso')\n\n async function login(type: LoginType) {\n setError('')\n setLoading(true)\n try {\n const data: LoginData = type === 'sso' ? { type: 'sso', email } : { type: 'idp', provider: 'external-idp:github' }\n await onSubmit(data)\n if (removeLoadingOnSuccess) setLoading(false)\n } catch (error: any) {\n setLoading(false)\n setError(error.message || error.toString())\n }\n }\n\n function submitForm(e: React.FormEvent<HTMLFormElement>) {\n e.preventDefault()\n if (disabled) return\n login('sso')\n }\n\n return (\n <>\n <LoginBox onSubmit={submitForm} className={className} style={style}>\n <header>\n <MiniLogo />\n <Text className=\"title\">{welcomeText || t.welcome}</Text>\n </header>\n {ssoLoginEnabled && <>\n <Input name=\"email\" value={email} onChange={e => setEmail(e.target.value)} placeholder={t.placeholder} />\n <Button colorScheme=\"primary\" disabled={disabled || loading}>\n {loading ? <LoadingCircular /> : <Text>{t.continue}</Text>}\n </Button>\n </>}\n {ssoLoginEnabled && idpLoginEnabled && <p className=\"separator\">{t.or}</p>}\n {idpLoginEnabled &&\n <Button colorScheme=\"light\" type=\"button\" onClick={() => login('idp')} disabled={loading}>\n {loading ? <LoadingCircular /> : (\n <>\n <IconBox>\n <Github />\n </IconBox>\n <Text>{t.loginWithGithub}</Text>\n </>\n )}\n </Button>}\n {error && <Text className=\"error\">{t.error}: {error}</Text>}\n </LoginBox>\n {banner ? <BannerWarning>\n {banner}\n </BannerWarning> : null}\n </>\n )\n}\n\nconst dictionary = {\n en: {\n welcome: 'Welcome to StackSpot',\n placeholder: 'your@email.com',\n continue: 'Continue',\n or: 'or',\n loginWithGithub: 'Login with Github',\n error: 'Error while attempting to login',\n },\n pt: {\n welcome: 'Bem vindo à StackSpot',\n placeholder: 'nome@email.com',\n continue: 'Continuar',\n or: 'ou',\n loginWithGithub: 'Logar com o GitHub',\n error: 'Erro ao fazer login',\n },\n} satisfies Dictionary\n","import { ThirdPartyLoginParams } from '@stack-spot/auth'\nimport { getCookie, getCookieDomain, removeCookie, setCookie } from '@stack-spot/portal-components'\n\nconst sessionKey = `stk-session${getCookieDomain()}`\n\ntype SessionCookie = ThirdPartyLoginParams & { sub: string }\n\nexport const sessionCookie = Object.freeze({\n set: (data: SessionCookie) => setCookie(sessionKey, JSON.stringify(data)),\n get: (): SessionCookie | undefined => {\n try {\n const cookie = getCookie(sessionKey)\n return cookie ? JSON.parse(cookie) : undefined\n } catch (error) {\n console.error(error)\n }\n },\n delete: () => removeCookie(sessionKey)\n})\n","export const redirect = async (url: string) => {\n window.location.href = url\n /**\n * This is intentional. The promise bellow will never be fulfilled.\n * Once the set href is not instantaneous, this will guarantee no further code is executed until the user is really redirected.\n * Particularly useful to prevent flickering page renders on scenarios with redirects.\n */\n await new Promise(() => '')\n}","import { AuthConfig, AuthManager, Session, ThirdPartyAuthType, ThirdPartyLoginParams } from '@stack-spot/auth'\nimport { sessionCookie } from './utils/cookies'\nimport { redirect } from './utils/redirect'\n\nconst sessionKey = 'session'\n\ninterface SessionManagerConfig extends Pick<AuthConfig, 'accountUrl' | 'authUrl' | 'clientId' | 'defaultTenant' | 'redirectUrl'> {\n loginUrl: string,\n blockedAuthTypes?: ThirdPartyAuthType[]\n rdUrl?: string,\n}\n\ntype AuthExtraData = { from?: string | null, finalRedirect?: string | null }\n\ntype ChangeListener = (session: Session | undefined) => void\n\n/**\n * Controls the current session in a browser.\n * \n * This should not be used under a Node.JS environment.\n * \n * This is a singleton. To create the first instance or recover the current one, use `SessionManager.create`.\n */\nexport class SessionManager {\n private current: Session | undefined\n private readonly auth: AuthManager<AuthExtraData>\n private config: SessionManagerConfig\n private changeListeners: ChangeListener[] = []\n static instance: SessionManager\n\n private constructor(config: SessionManagerConfig) {\n this.config = config\n this.auth = new AuthManager<AuthExtraData>({\n ...config,\n storage: localStorage,\n sessionPersistence: {\n load: () => localStorage.getItem(sessionKey),\n save: (session) => localStorage.setItem(sessionKey, session),\n },\n })\n SessionManager.instance = this\n\n // Keep session in sync with other app's session\n addEventListener('focus', () => this.validateSharedSession())\n }\n\n static create(config: SessionManagerConfig) {\n return SessionManager.instance ?? new SessionManager(config)\n }\n\n private setSession(session: Session | undefined) {\n this.current = session\n this.changeListeners.forEach(l => l(session))\n if (session) this.setSessionCookie(session)\n }\n\n async restoreSession() {\n const session = await this.auth.restoreSession()\n const sessionValid = await this.validateSharedSession(session)\n this.setSession(sessionValid ? session : undefined)\n }\n\n async validateSharedSession(session: Session | undefined = this.current): Promise<boolean> {\n\n // skipping because authentication is in progress\n if (this.urlHasThirdPartyLoginData()) return false\n\n const sharedSessionCookie = sessionCookie.get()\n\n // It has been logged out on another portal, so logout on this one too\n if (!sharedSessionCookie) {\n session && await this.logout()\n return false\n }\n\n const isDifferentSessionActive = sharedSessionCookie.sub != session?.getTokenData().sub\n const isSharedSessionTypeBlocked = this.config.blockedAuthTypes?.includes(sharedSessionCookie.type)\n if (isSharedSessionTypeBlocked) return false\n else if (isDifferentSessionActive || !session) {\n await this.startThirdPartyLogin(sharedSessionCookie)\n return false\n }\n return true\n }\n\n hasSession() {\n return !!this.current && !this.current.isExpired()\n }\n\n getSession() {\n if (!this.hasSession()) {\n this.endSession()\n throw new Error('Session is not available, redirecting to login.')\n }\n return this.current!\n }\n\n async endSession(redirectToLogin = true) {\n this.current = undefined\n localStorage.removeItem(sessionKey)\n sessionCookie.delete()\n if (redirectToLogin) await redirect(this.config.loginUrl)\n }\n\n async logout() {\n try {\n await this.current?.logout()\n } catch (error) {\n // eslint-disable-next-line no-console\n console.error(`Could not logout from IDM.\\n${error}`)\n }\n await this.endSession()\n }\n\n async startThirdPartyLogin(data: ThirdPartyLoginParams) {\n const params = new URLSearchParams(location.search)\n const authUrl = await this.auth.startThirdPartyLogin(data, {\n from: location.href,\n finalRedirect: params.get('finalRedirect'),\n })\n await redirect(authUrl)\n }\n\n urlHasThirdPartyLoginData() {\n const url = new URL(location.toString())\n return url.searchParams.has('state') && !url.searchParams.has('error')\n }\n\n async completeThirdPartyLogin() {\n const url = new URL(location.toString())\n if (url.searchParams.has('error')) {\n throw new Error(`Error while signing in: ${url.searchParams.get('error_description')}`)\n }\n const { session, data: { from, finalRedirect } } = await this.auth.completeThirdPartyLogin(location.search)\n this.setSession(session)\n history.replaceState(null, '', from || location.toString().replace(/\\?.*$/, ''))\n this.sendLoginEventRd(this.current?.getTokenData().email, this.current?.getTokenData().name)\n if (finalRedirect) await redirect(finalRedirect)\n }\n\n getEmailForLogin() {\n const session = sessionCookie.get()\n return session?.type == 'sso' ? session.email : undefined\n }\n\n async switchAccount(accountId: string) {\n this.current && await this.auth.switchAccount(accountId, this.current)\n this.setSession(this.current)\n }\n\n onChange(listener: ChangeListener) {\n this.changeListeners.push(listener)\n return () => {\n const index = this.changeListeners.indexOf(listener)\n if (index != -1) this.changeListeners.splice(index, 1)\n }\n }\n\n private setSessionCookie(session: Session) {\n const { email, account_type, sub } = session.getTokenData()\n if (!email || !sub) return\n const isFreemium = account_type == 'FREEMIUM'\n if (isFreemium) {\n sessionCookie.set({ type: 'idp', provider: 'external-idp:github', sub })\n } else {\n sessionCookie.set({ email, type: 'sso', sub })\n }\n }\n\n private async sendLoginEventRd(email?: string, name?: string) {\n if (!this.config.rdUrl) return\n if (!email && !name) {\n // eslint-disable-next-line no-console\n console.error('Unable to trigger login hook. No sessionEmail or name identified.')\n return\n }\n\n const rdObject = {\n event_type: 'CONVERSION',\n event_family: 'CDP',\n payload: {\n email,\n name,\n conversion_identifier: 'login-v1',\n },\n }\n\n const response = await fetch(this.config.rdUrl, {\n method: 'POST',\n body: JSON.stringify(rdObject),\n headers: {\n 'content-type': 'application/json',\n },\n })\n const data = await response.json()\n\n if (!response.ok) {\n // eslint-disable-next-line no-console\n console.error('Error while sending event to RD Station', data)\n }\n }\n}\n","/* eslint-disable max-len */\nimport { Flex } from '@citric/core'\nimport { useEffectOnce } from '@stack-spot/portal-components'\nimport { CSSToCitricAdapter } from '@stack-spot/portal-theme'\nimport '@stack-spot/portal-theme/dist/theme.css'\nimport { useLanguage } from '@stack-spot/portal-translate'\nimport { useState } from 'react'\nimport { Login, LoginProps } from './Login'\nimport { SessionManager } from './SessionManager'\n\ntype AuthStatus = 'unknown' | 'authenticated' | 'unauthenticated'\n\ninterface Props {\n children: React.ReactElement\n onLogin?: () => void\n onSession?: () => void\n customLoginProps?: Omit<LoginProps, 'onSubmit' | 'initialValue'>\n}\n\nexport const Authenticated = ({ children, onLogin, onSession, customLoginProps }: Props) => {\n const [authStatus, setAuthStatus] = useState<AuthStatus>('unknown')\n const language = useLanguage()\n const sessionManager = SessionManager.instance\n\n useEffectOnce(() => {\n async function checkAuth() {\n await sessionManager.restoreSession()\n if (sessionManager.urlHasThirdPartyLoginData()) {\n await sessionManager.completeThirdPartyLogin()\n onLogin?.()\n }\n if (sessionManager.hasSession()) {\n setAuthStatus('authenticated')\n onSession?.()\n } else {\n setAuthStatus('unauthenticated')\n }\n }\n\n checkAuth()\n })\n\n if (authStatus === 'unknown') return null\n if (authStatus === 'authenticated') return children\n\n return (\n <CSSToCitricAdapter>\n <Flex justifyContent=\"center\" alignItems=\"center\" flex={1} style={{ height: '100%' }}>\n <Login\n style={{ width: '360px' }}\n onSubmit={data => sessionManager.startThirdPartyLogin({ ...data, locale: language })}\n initialValue={sessionManager.getEmailForLogin()}\n {...(customLoginProps || {})}\n />\n </Flex>\n </CSSToCitricAdapter>\n )\n}\n","import { Session } from '@stack-spot/auth'\nimport { useEffect, useState } from 'react'\nimport { SessionManager } from './SessionManager'\n\nexport function useSession() {\n const manager = SessionManager.instance\n const [session, setSession] = useState<Session | undefined>(manager?.hasSession() ? manager.getSession() : undefined)\n useEffect(() => {\n return manager?.onChange(setSession)\n }, [])\n return session\n}\n"],"names":["error","sessionKey","__spreadProps","__spreadValues"],"mappings":";;;;;;;;;;;;;AAwCA,MAAM,WAAW,MAAO,CAAA,IAAA,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAAA,EAmBA,KAAM,CAAA,KAAA,CAAM,KAAM,CAAA,KAAK,CAAC,CAAA;AAAA,WAAA,EACnC,KAAM,CAAA,KAAA,CAAM,KAAM,CAAA,KAAK,CAAC,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAAA,EAYX,KAAM,CAAA,KAAA,CAAM,KAAM,CAAA,KAAK,CAAC,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA,WAAA,EAKrC,KAAM,CAAA,KAAA,CAAM,MAAO,CAAA,KAAK,CAAC,CAAA;AAAA;AAAA;AAAA,CAAA,CAAA;AAK/B,MAAM,QAAQ,CAAC,EAAE,QAAU,EAAA,YAAA,GAAe,IAAI,WAAa,EAAA,sBAAA,EAAwB,SAAW,EAAA,KAAA,EAAO,QAAQ,UAAa,GAAA,CAAC,KAAO,EAAA,KAAK,GAAoB,KAAA;AAChK,EAAM,MAAA,CAAA,GAAI,aAAa,UAAU,CAAA,CAAA;AACjC,EAAA,MAAM,YAAe,GAAA,IAAI,eAAgB,CAAA,QAAA,CAAS,MAAM,CAAA,CAAA;AACxD,EAAA,MAAM,CAAC,KAAA,EAAO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AAa,GAAA;AAC3B,EAAA,MAAM,UAAU,cAAe,CAAA,QAAA,CAAA;AAC/B,EAAM,MAAA,CAAC,OAAS,EAAA,UAAU,CAAI,GAAA,QAAA,CAAA,CAA8B,mCAAS,UAAe,EAAA,IAAA,OAAA,CAAQ,UAAW,EAAA,GAAI,KAAS,CAAA,CAAA,CAAA;AACpH,EAAA,SAAA,CAAU,MAAM;AACd,IAAA,OAAO,mCAAS,QAAS,CAAA,UAAA,CAAA,CAAA;AAAA,GAC3B,EAAG,EAAE,CAAA,CAAA;AACL,EAAO,OAAA,OAAA,CAAA;AACT;;;;"}
|
package/package.json
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stack-spot/auth-react",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"main": "out/index.js",
|
|
5
5
|
"module": "out/index.mjs",
|
|
6
6
|
"typings": "out/index.d.ts",
|
|
7
|
-
"scripts": {
|
|
8
|
-
"compile": "rollup -c",
|
|
9
|
-
"build": "pnpm compile"
|
|
10
|
-
},
|
|
11
7
|
"devDependencies": {
|
|
12
8
|
"@typescript-eslint/eslint-plugin": "^6.21.0",
|
|
13
9
|
"@typescript-eslint/parser": "^6.21.0",
|
|
@@ -16,13 +12,24 @@
|
|
|
16
12
|
"rollup": "^3.26.3",
|
|
17
13
|
"rollup-plugin-dts": "^5.3.0",
|
|
18
14
|
"rollup-plugin-esbuild": "^5.0.0",
|
|
19
|
-
"typescript": "^
|
|
15
|
+
"typescript": "^5.2.2",
|
|
20
16
|
"@types/react": "^18.2.37",
|
|
21
17
|
"@types/react-dom": "^18.2.15"
|
|
22
18
|
},
|
|
23
19
|
"peerDependencies": {
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"@
|
|
20
|
+
"@citric/core": "^5.0.0 || ^6.0.0",
|
|
21
|
+
"@citric/icons": "^5.0.0",
|
|
22
|
+
"@citric/ui": "^5.0.0 || ^6.0.0",
|
|
23
|
+
"@stack-spot/auth": "^5.0.0",
|
|
24
|
+
"@stack-spot/portal-theme": "^1.0.0",
|
|
25
|
+
"@stack-spot/portal-components": "^1.0.0",
|
|
26
|
+
"@stack-spot/portal-translate": "^1.0.0",
|
|
27
|
+
"react": "^18.2.0",
|
|
28
|
+
"react-dom": "^18.2.0",
|
|
29
|
+
"styled-components": "^6.1.10"
|
|
30
|
+
},
|
|
31
|
+
"scripts": {
|
|
32
|
+
"compile": "rollup -c",
|
|
33
|
+
"build": "pnpm compile"
|
|
27
34
|
}
|
|
28
35
|
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/* eslint-disable max-len */
|
|
2
|
+
import { Flex } from '@citric/core'
|
|
3
|
+
import { useEffectOnce } from '@stack-spot/portal-components'
|
|
4
|
+
import { CSSToCitricAdapter } from '@stack-spot/portal-theme'
|
|
5
|
+
import '@stack-spot/portal-theme/dist/theme.css'
|
|
6
|
+
import { useLanguage } from '@stack-spot/portal-translate'
|
|
7
|
+
import { useState } from 'react'
|
|
8
|
+
import { Login, LoginProps } from './Login'
|
|
9
|
+
import { SessionManager } from './SessionManager'
|
|
10
|
+
|
|
11
|
+
type AuthStatus = 'unknown' | 'authenticated' | 'unauthenticated'
|
|
12
|
+
|
|
13
|
+
interface Props {
|
|
14
|
+
children: React.ReactElement
|
|
15
|
+
onLogin?: () => void
|
|
16
|
+
onSession?: () => void
|
|
17
|
+
customLoginProps?: Omit<LoginProps, 'onSubmit' | 'initialValue'>
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const Authenticated = ({ children, onLogin, onSession, customLoginProps }: Props) => {
|
|
21
|
+
const [authStatus, setAuthStatus] = useState<AuthStatus>('unknown')
|
|
22
|
+
const language = useLanguage()
|
|
23
|
+
const sessionManager = SessionManager.instance
|
|
24
|
+
|
|
25
|
+
useEffectOnce(() => {
|
|
26
|
+
async function checkAuth() {
|
|
27
|
+
await sessionManager.restoreSession()
|
|
28
|
+
if (sessionManager.urlHasThirdPartyLoginData()) {
|
|
29
|
+
await sessionManager.completeThirdPartyLogin()
|
|
30
|
+
onLogin?.()
|
|
31
|
+
}
|
|
32
|
+
if (sessionManager.hasSession()) {
|
|
33
|
+
setAuthStatus('authenticated')
|
|
34
|
+
onSession?.()
|
|
35
|
+
} else {
|
|
36
|
+
setAuthStatus('unauthenticated')
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
checkAuth()
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
if (authStatus === 'unknown') return null
|
|
44
|
+
if (authStatus === 'authenticated') return children
|
|
45
|
+
|
|
46
|
+
return (
|
|
47
|
+
<CSSToCitricAdapter>
|
|
48
|
+
<Flex justifyContent="center" alignItems="center" flex={1} style={{ height: '100%' }}>
|
|
49
|
+
<Login
|
|
50
|
+
style={{ width: '360px' }}
|
|
51
|
+
onSubmit={data => sessionManager.startThirdPartyLogin({ ...data, locale: language })}
|
|
52
|
+
initialValue={sessionManager.getEmailForLogin()}
|
|
53
|
+
{...(customLoginProps || {})}
|
|
54
|
+
/>
|
|
55
|
+
</Flex>
|
|
56
|
+
</CSSToCitricAdapter>
|
|
57
|
+
)
|
|
58
|
+
}
|
package/src/Login.tsx
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/* eslint-disable max-len */
|
|
2
|
+
import { Button, IconBox, Input, Text } from '@citric/core'
|
|
3
|
+
import { Github } from '@citric/icons'
|
|
4
|
+
import { LoadingCircular } from '@citric/ui'
|
|
5
|
+
import { BannerWarning } from '@stack-spot/portal-components'
|
|
6
|
+
import { MiniLogo } from '@stack-spot/portal-components/svg'
|
|
7
|
+
import { theme } from '@stack-spot/portal-theme'
|
|
8
|
+
import { Dictionary, useTranslate } from '@stack-spot/portal-translate'
|
|
9
|
+
import { useState } from 'react'
|
|
10
|
+
import { styled } from 'styled-components'
|
|
11
|
+
|
|
12
|
+
export type LoginType = 'sso' | 'idp'
|
|
13
|
+
|
|
14
|
+
interface BaseData {
|
|
15
|
+
type: LoginType,
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
interface SSOData extends BaseData {
|
|
19
|
+
type: 'sso',
|
|
20
|
+
email: string,
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
interface IDPData extends BaseData {
|
|
24
|
+
type: 'idp',
|
|
25
|
+
provider: 'external-idp:github',
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
type LoginData = SSOData | IDPData
|
|
29
|
+
|
|
30
|
+
export type LoginProps = {
|
|
31
|
+
initialValue?: string,
|
|
32
|
+
onSubmit: (data: LoginData) => Promise<void>,
|
|
33
|
+
welcomeText?: string,
|
|
34
|
+
removeLoadingOnSuccess?: boolean,
|
|
35
|
+
className?: string,
|
|
36
|
+
style?: React.CSSProperties,
|
|
37
|
+
banner?: React.ReactNode,
|
|
38
|
+
loginTypes?: LoginType[]
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const LoginBox = styled.form`
|
|
42
|
+
display: flex;
|
|
43
|
+
flex-direction: column;
|
|
44
|
+
justify-content: center;
|
|
45
|
+
gap: 24px;
|
|
46
|
+
|
|
47
|
+
header {
|
|
48
|
+
display: flex;
|
|
49
|
+
flex-direction: column;
|
|
50
|
+
align-items: center;
|
|
51
|
+
gap: 24px;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
.title {
|
|
55
|
+
font-size: 1rem;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
.separator {
|
|
59
|
+
padding: 0 8px;
|
|
60
|
+
background-color: ${theme.color.light['400']};
|
|
61
|
+
color: ${theme.color.light['700']};
|
|
62
|
+
display: flex;
|
|
63
|
+
flex-direction: row;
|
|
64
|
+
align-items: center;
|
|
65
|
+
justify-content: center;
|
|
66
|
+
gap: 20px;
|
|
67
|
+
margin: 0;
|
|
68
|
+
|
|
69
|
+
&:before, &:after {
|
|
70
|
+
content: '';
|
|
71
|
+
height: 1px;
|
|
72
|
+
flex: 1;
|
|
73
|
+
background-color: ${theme.color.light['600']};
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
.error {
|
|
78
|
+
color: ${theme.color.danger['500']};
|
|
79
|
+
line-height: 1.5rem;
|
|
80
|
+
}
|
|
81
|
+
`
|
|
82
|
+
|
|
83
|
+
export const Login = ({ onSubmit, initialValue = '', welcomeText, removeLoadingOnSuccess, className, style, banner, loginTypes = ['idp', 'sso'] }: LoginProps) => {
|
|
84
|
+
const t = useTranslate(dictionary)
|
|
85
|
+
const searchParams = new URLSearchParams(location.search)
|
|
86
|
+
const [error, setError] = useState(searchParams.get('error_description') || searchParams.get('error') || '')
|
|
87
|
+
const [loading, setLoading] = useState(false)
|
|
88
|
+
const [email, setEmail] = useState(initialValue)
|
|
89
|
+
const disabled = !email.match(/\w+@\w+/)
|
|
90
|
+
const idpLoginEnabled = loginTypes.includes('idp')
|
|
91
|
+
const ssoLoginEnabled = loginTypes.includes('sso')
|
|
92
|
+
|
|
93
|
+
async function login(type: LoginType) {
|
|
94
|
+
setError('')
|
|
95
|
+
setLoading(true)
|
|
96
|
+
try {
|
|
97
|
+
const data: LoginData = type === 'sso' ? { type: 'sso', email } : { type: 'idp', provider: 'external-idp:github' }
|
|
98
|
+
await onSubmit(data)
|
|
99
|
+
if (removeLoadingOnSuccess) setLoading(false)
|
|
100
|
+
} catch (error: any) {
|
|
101
|
+
setLoading(false)
|
|
102
|
+
setError(error.message || error.toString())
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function submitForm(e: React.FormEvent<HTMLFormElement>) {
|
|
107
|
+
e.preventDefault()
|
|
108
|
+
if (disabled) return
|
|
109
|
+
login('sso')
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return (
|
|
113
|
+
<>
|
|
114
|
+
<LoginBox onSubmit={submitForm} className={className} style={style}>
|
|
115
|
+
<header>
|
|
116
|
+
<MiniLogo />
|
|
117
|
+
<Text className="title">{welcomeText || t.welcome}</Text>
|
|
118
|
+
</header>
|
|
119
|
+
{ssoLoginEnabled && <>
|
|
120
|
+
<Input name="email" value={email} onChange={e => setEmail(e.target.value)} placeholder={t.placeholder} />
|
|
121
|
+
<Button colorScheme="primary" disabled={disabled || loading}>
|
|
122
|
+
{loading ? <LoadingCircular /> : <Text>{t.continue}</Text>}
|
|
123
|
+
</Button>
|
|
124
|
+
</>}
|
|
125
|
+
{ssoLoginEnabled && idpLoginEnabled && <p className="separator">{t.or}</p>}
|
|
126
|
+
{idpLoginEnabled &&
|
|
127
|
+
<Button colorScheme="light" type="button" onClick={() => login('idp')} disabled={loading}>
|
|
128
|
+
{loading ? <LoadingCircular /> : (
|
|
129
|
+
<>
|
|
130
|
+
<IconBox>
|
|
131
|
+
<Github />
|
|
132
|
+
</IconBox>
|
|
133
|
+
<Text>{t.loginWithGithub}</Text>
|
|
134
|
+
</>
|
|
135
|
+
)}
|
|
136
|
+
</Button>}
|
|
137
|
+
{error && <Text className="error">{t.error}: {error}</Text>}
|
|
138
|
+
</LoginBox>
|
|
139
|
+
{banner ? <BannerWarning>
|
|
140
|
+
{banner}
|
|
141
|
+
</BannerWarning> : null}
|
|
142
|
+
</>
|
|
143
|
+
)
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const dictionary = {
|
|
147
|
+
en: {
|
|
148
|
+
welcome: 'Welcome to StackSpot',
|
|
149
|
+
placeholder: 'your@email.com',
|
|
150
|
+
continue: 'Continue',
|
|
151
|
+
or: 'or',
|
|
152
|
+
loginWithGithub: 'Login with Github',
|
|
153
|
+
error: 'Error while attempting to login',
|
|
154
|
+
},
|
|
155
|
+
pt: {
|
|
156
|
+
welcome: 'Bem vindo à StackSpot',
|
|
157
|
+
placeholder: 'nome@email.com',
|
|
158
|
+
continue: 'Continuar',
|
|
159
|
+
or: 'ou',
|
|
160
|
+
loginWithGithub: 'Logar com o GitHub',
|
|
161
|
+
error: 'Erro ao fazer login',
|
|
162
|
+
},
|
|
163
|
+
} satisfies Dictionary
|
package/src/index.ts
CHANGED
package/src/utils/cookies.ts
CHANGED
|
@@ -1,29 +1,10 @@
|
|
|
1
|
-
import { ThirdPartyLoginParams } from
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
const portalUrl = new URL(location.href)
|
|
5
|
-
const cookieDomain = DOMAIN_REGEX.exec(portalUrl.host)?.[0]
|
|
6
|
-
const defaultCookieAttributes = `domain=${cookieDomain}; SameSite=Strict;`
|
|
7
|
-
const sessionKey = `stk-session${cookieDomain}`
|
|
8
|
-
|
|
9
|
-
const setCookie = (key: string, value: string) => {
|
|
10
|
-
document.cookie = `${key}=${value}; ${defaultCookieAttributes}`
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const removeCookie = (key: string) => {
|
|
14
|
-
document.cookie = `${key}=; max-age=0; ${defaultCookieAttributes}`
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const getCookie = (key: string) => getCookies()[key]
|
|
18
|
-
|
|
19
|
-
const getCookies = (): Record<string, string> => document.cookie.split('; ').reduce((prev, current) => {
|
|
20
|
-
const [name, ...value] = current.split('=')
|
|
21
|
-
prev[name] = value.join('=')
|
|
22
|
-
return prev
|
|
23
|
-
}, {} as Record<string, string>)
|
|
1
|
+
import { ThirdPartyLoginParams } from '@stack-spot/auth'
|
|
2
|
+
import { getCookie, getCookieDomain, removeCookie, setCookie } from '@stack-spot/portal-components'
|
|
24
3
|
|
|
4
|
+
const sessionKey = `stk-session${getCookieDomain()}`
|
|
25
5
|
|
|
26
6
|
type SessionCookie = ThirdPartyLoginParams & { sub: string }
|
|
7
|
+
|
|
27
8
|
export const sessionCookie = Object.freeze({
|
|
28
9
|
set: (data: SessionCookie) => setCookie(sessionKey, JSON.stringify(data)),
|
|
29
10
|
get: (): SessionCookie | undefined => {
|
|
@@ -35,4 +16,4 @@ export const sessionCookie = Object.freeze({
|
|
|
35
16
|
}
|
|
36
17
|
},
|
|
37
18
|
delete: () => removeCookie(sessionKey)
|
|
38
|
-
})
|
|
19
|
+
})
|
package/src/utils/redirect.ts
CHANGED
package/tsconfig.json
CHANGED
package/src/utils/regex.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const DOMAIN_REGEX = new RegExp(/(\.*(prd|stg|dev)*.stackspot.com)|localhost/)
|