diff --git a/.gitignore b/.gitignore index 0d9682f..76c2c72 100644 --- a/.gitignore +++ b/.gitignore @@ -22,4 +22,6 @@ npm-debug.log* yarn-debug.log* yarn-error.log* -lib/node_modules \ No newline at end of file +lib/node_modules +dist/ +lib/dist/ \ No newline at end of file diff --git a/lib/dist/lib/src/index.d.ts b/lib/dist/lib/src/index.d.ts deleted file mode 100644 index dfa0dfc..0000000 --- a/lib/dist/lib/src/index.d.ts +++ /dev/null @@ -1 +0,0 @@ -export { createZITADELAuth, ZitadelConfig } from "./zitadelAuth"; diff --git a/lib/dist/lib/src/index.js b/lib/dist/lib/src/index.js deleted file mode 100644 index 921a4f5..0000000 --- a/lib/dist/lib/src/index.js +++ /dev/null @@ -1 +0,0 @@ -export { createZITADELAuth } from "./zitadelAuth"; diff --git a/lib/dist/lib/src/zitadelAuth.d.ts b/lib/dist/lib/src/zitadelAuth.d.ts deleted file mode 100644 index 831795c..0000000 --- a/lib/dist/lib/src/zitadelAuth.d.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { UserManager } from "oidc-client-ts"; -export interface ZitadelConfig { - client_id: string; - issuer: string; - project_resource_id?: string; -} -interface ZitadelAuth { - authorize(): Promise; - clearAuth(): Promise; - userManager: UserManager; -} -export declare function createZITADELAuth(zitadelConfig: ZitadelConfig): ZitadelAuth; -export {}; diff --git a/lib/dist/lib/src/zitadelAuth.js b/lib/dist/lib/src/zitadelAuth.js deleted file mode 100644 index 4962ea2..0000000 --- a/lib/dist/lib/src/zitadelAuth.js +++ /dev/null @@ -1,33 +0,0 @@ -import { UserManager, WebStorageStateStore, } from "oidc-client-ts"; -export function createZITADELAuth(zitadelConfig) { - const authConfig = { - authority: `${zitadelConfig.issuer}`, //Replace with your issuer URL - client_id: `${zitadelConfig.client_id}`, //Replace with your client id - redirect_uri: "http://localhost:3000/callback", - response_type: "code", - scope: `openid profile email ${zitadelConfig.project_resource_id - ? `urn:zitadel:iam:org:project:id:${zitadelConfig.project_resource_id}:aud urn:zitadel:iam:org:projects:roles` - : ""}`, - post_logout_redirect_uri: "http://localhost:3000/", - // userinfo_endpoint: - // "https://instance-some_text.zitadel.cloud/oidc/v1/userinfo", - response_mode: "query", - // code_challenge_method: "S256", - }; - const userManager = new UserManager({ - userStore: new WebStorageStateStore({ store: window.localStorage }), - ...authConfig, - }); - const authorize = () => { - return userManager.signinRedirect(); - }; - const clearAuth = () => { - return userManager.signoutRedirect(); - }; - const oidc = { - authorize, - clearAuth, - userManager, - }; - return oidc; -} diff --git a/lib/dist/src/components/Callback.d.ts b/lib/dist/src/components/Callback.d.ts deleted file mode 100644 index 18b090a..0000000 --- a/lib/dist/src/components/Callback.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -/// -type Props = { - authenticated: boolean; - setAuth: (authenticated: boolean) => void; - userManager: any; - userInfo: any; - setUserInfo: any; - handleLogout: any; -}; -declare const Callback: ({ authenticated, setAuth, userManager, userInfo, setUserInfo, handleLogout, }: Props) => import("react").JSX.Element; -export default Callback; diff --git a/lib/dist/src/components/Callback.js b/lib/dist/src/components/Callback.js deleted file mode 100644 index a724348..0000000 --- a/lib/dist/src/components/Callback.js +++ /dev/null @@ -1,48 +0,0 @@ -import { useEffect } from "react"; -const Callback = ({ authenticated, setAuth, userManager, userInfo, setUserInfo, handleLogout, }) => { - useEffect(() => { - if (authenticated === false) { - userManager - .signinRedirectCallback() - .then((user) => { - if (user) { - setAuth(true); - const access_token = user.access_token; - // Make a request to the user info endpoint using the access token - // fetch(authConfig.userinfo_endpoint, { - // headers: { - // 'Authorization': `Bearer ${access_token}` - // } - // }) - // .then(response => response.json()) - // .then(userInfo => { - // setUserInfo(userInfo); - // }); - } - else { - setAuth(false); - } - }) - .catch((error) => { - setAuth(false); - }); - } - }, [authenticated, userManager, setAuth]); - console.log(authenticated, userInfo); - if (authenticated === true && userInfo) { - return (
-

Welcome, {userInfo.name}!

-

Your ZITADEL Profile Information

-

Name: {userInfo.name}

-

Email: {userInfo.email}

-

Email Verified: {userInfo.email_verified ? "Yes" : "No"}

-

Locale: {userInfo.locale}

- - -
); - } - else { - return
Loading...
; - } -}; -export default Callback; diff --git a/lib/dist/src/components/Login.d.ts b/lib/dist/src/components/Login.d.ts deleted file mode 100644 index 37efb5e..0000000 --- a/lib/dist/src/components/Login.d.ts +++ /dev/null @@ -1,7 +0,0 @@ -/// -type Props = { - handleLogin: () => void; - authenticated: boolean; -}; -declare const Login: ({ authenticated, handleLogin }: Props) => import("react").JSX.Element; -export default Login; diff --git a/lib/dist/src/components/Login.js b/lib/dist/src/components/Login.js deleted file mode 100644 index e78d88b..0000000 --- a/lib/dist/src/components/Login.js +++ /dev/null @@ -1,17 +0,0 @@ -import { Navigate } from "react-router-dom"; -const Login = ({ authenticated, handleLogin }) => { - return (
- {authenticated === null &&
Loading...
} - {authenticated === false && (
-

Welcome!

- -
)} - {authenticated && } -
); -}; -export default Login; diff --git a/src/App.css b/src/App.css index 671af81..65c9b1e 100644 --- a/src/App.css +++ b/src/App.css @@ -37,6 +37,15 @@ button { border: 1px solid #333333; } +.user { + font-size: 1rem; +} + +.user .description { + font-size: 1rem; + margin-bottom: 1rem; +} + @keyframes App-logo-spin { from { transform: rotate(0deg); diff --git a/src/App.tsx b/src/App.tsx index b7c73d7..8ac2d78 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -23,7 +23,7 @@ function App() { zitadel.signout(); } - const [authenticated, setAuthenticated] = useState(false); + const [authenticated, setAuthenticated] = useState(null); const [userInfo, setUserInfo] = useState(null); useEffect(() => { diff --git a/src/components/Callback.tsx b/src/components/Callback.tsx index a2d1fc2..4446c92 100644 --- a/src/components/Callback.tsx +++ b/src/components/Callback.tsx @@ -2,8 +2,8 @@ import { useEffect } from "react"; type Props = { issuer: string; - authenticated: boolean; - setAuth: (authenticated: boolean) => void; + authenticated: boolean | null; + setAuth: (authenticated: boolean | null) => void; userManager: any; userInfo: any; setUserInfo: any; @@ -19,9 +19,8 @@ const Callback = ({ handleLogout, }: Props) => { useEffect(() => { - if (authenticated === false) { - userManager - .signinRedirectCallback() + if (authenticated === null || userInfo === null) { + userManager() .then((user: any) => { if (user) { setAuth(true); @@ -45,12 +44,11 @@ const Callback = ({ }); } }, [authenticated, userManager, setAuth]); - console.log(authenticated, userInfo); if (authenticated === true && userInfo) { return ( -
+

Welcome, {userInfo.name}!

-

Your ZITADEL Profile Information

+

Your ZITADEL Profile Information

Name: {userInfo.name}

Email: {userInfo.email}

Email Verified: {userInfo.email_verified ? "Yes" : "No"}

diff --git a/src/components/Login.tsx b/src/components/Login.tsx index d574bd2..ee48bc6 100644 --- a/src/components/Login.tsx +++ b/src/components/Login.tsx @@ -2,7 +2,7 @@ import { Navigate } from "react-router-dom"; type Props = { handleLogin: () => void; - authenticated: boolean; + authenticated: boolean | null; }; const Login = ({ authenticated, handleLogin }: Props) => { return (