Skip to content
This repository has been archived by the owner on Sep 6, 2024. It is now read-only.

Feat/login UI #73

Merged
merged 24 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
3ce785d
start of login page
jamieknight-db Aug 9, 2024
bb381ea
env and google auth button
jamieknight-db Aug 12, 2024
91021d5
Merge branch 'refs/heads/main' into feat/login-ui
jamieknight-db Aug 12, 2024
661f2eb
merge with main, remove params reference
jamieknight-db Aug 12, 2024
5a6faa4
Merge branch 'refs/heads/main' into feat/login-ui
jamieknight-db Aug 12, 2024
a29a2ce
start of okta auth
jamieknight-db Aug 13, 2024
c615a42
initial commit for handling auth token (#67)
xx-db Aug 15, 2024
950f727
start of login with keycloak
jamieknight-db Aug 15, 2024
4ec0f85
handle google sign in with token
jamieknight-db Aug 19, 2024
ab0e00e
more google auth
jamieknight-db Aug 19, 2024
f9bf937
profile dropdown
jamieknight-db Aug 21, 2024
1fdd8da
Merge branch 'refs/heads/main' into feat/login-ui
jamieknight-db Aug 22, 2024
869a7b3
merge with main
jamieknight-db Aug 22, 2024
3724067
Merge branch 'refs/heads/main' into feat/login-ui
jamieknight-db Aug 22, 2024
f0f6cdf
merge with main
jamieknight-db Aug 22, 2024
01deadc
convert to axios
jamieknight-db Aug 22, 2024
1f0c379
start of readme instructions
jamieknight-db Aug 22, 2024
261cc1a
get current user endpoint (#70)
xx-db Aug 26, 2024
8cbc0bd
commenting out UI until repositories are merged
jamieknight-db Aug 28, 2024
2e6368c
clean up current user (#74)
xx-db Aug 28, 2024
30a2e52
yarn lock file
jamieknight-db Aug 28, 2024
8557b8c
remove keycloak for now, node version error in jwt-decode dependency
jamieknight-db Aug 28, 2024
2228456
commit yarn lock
jamieknight-db Aug 28, 2024
b381de0
remove state as useEffect dependency, comment out currentUser call fo…
jamieknight-db Aug 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Google config
REACT_APP_GOOGLE_AUTH_ENABLED=false
REACT_APP_GOOGLE_CLIENT_ID=

# Okta config
REACT_APP_OKTA_AUTH_ENABLED=false
REACT_APP_OKTA_DOMAIN=
REACT_APP_OKTA_CLIENT_ID=

# Keycloak config
REACT_APP_KEYCLOAK_AUTH_ENABLED=false
REACT_APP_KEYCLOAK_URL=
REACT_APP_KEYCLOAK_REALM_ID=
REACT_APP_KEYCLOAK_CLIENT_ID=
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,10 @@ Open [http://localhost:3000](http://localhost:3000) to view it in the browser.

The page will reload if you make edits.\
You will also see any lint errors in the console.


### Authenticate and Login

OSS Unity Catalog supports Sign in with Google. You can authenticate with Google by clicking the "Sign in with Google" button on the login page, once OAuth has been configured. To configure this, follow the steps to obtain a [Google API Client ID](https://developers.google.com/identity/gsi/web/guides/get-google-api-clientid) and configure your OAuth consent screen.

Once you have the client ID, add it to the `.env` file after `REACT_APP_GOOGLE_CLIENT_ID=` and change the `REACT_APP_GOOGLE_AUTH_ENABLED` flag from false to true. Restart yarn.
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
"proxy": "http://localhost:8080",
"dependencies": {
"@ant-design/icons": "^5.3.7",
"@okta/okta-auth-js": "^7.7.0",
"@okta/okta-signin-widget": "^7.21.0",
"@tanstack/react-query": "^5.50.1",
"@testing-library/jest-dom": "^5.14.1",
"@testing-library/react": "^13.0.0",
"@testing-library/user-event": "^13.2.1",
"antd": "^5.19.1",
"axios": "^1.7.4",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-router-dom": "^6.24.1",
Expand Down Expand Up @@ -52,4 +55,4 @@
"@types/react-dom": "^18.0.0",
"prettier": "^3.3.3"
}
}
}
10 changes: 10 additions & 0 deletions public/keycloak-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/okta-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions public/uc-logo-horiz-reverse.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
118 changes: 99 additions & 19 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import React from 'react';
import { ConfigProvider, Layout, Menu } from 'antd';
import React, { useMemo } from 'react';
import {
Avatar,

Check warning on line 3 in src/App.tsx

View workflow job for this annotation

GitHub Actions / lint

'Avatar' is defined but never used
ConfigProvider,
Dropdown,

Check warning on line 5 in src/App.tsx

View workflow job for this annotation

GitHub Actions / lint

'Dropdown' is defined but never used
Layout,
Menu,
MenuProps,
Typography,
} from 'antd';
import {
createBrowserRouter,
Outlet,
Expand All @@ -16,6 +24,9 @@
import CatalogDetails from './pages/CatalogDetails';
import SchemaDetails from './pages/SchemaDetails';
import { NotificationProvider } from './utils/NotificationContext';
import Login from './pages/Login';

Check warning on line 27 in src/App.tsx

View workflow job for this annotation

GitHub Actions / lint

'Login' is defined but never used
import { AuthProvider, useAuth } from './context/auth-context';
import { UserOutlined } from '@ant-design/icons';

Check warning on line 29 in src/App.tsx

View workflow job for this annotation

GitHub Actions / lint

'UserOutlined' is defined but never used

const router = createBrowserRouter([
{
Expand Down Expand Up @@ -50,8 +61,43 @@
]);

function AppProvider() {
const { accessToken, logout } = useAuth();
const navigate = useNavigate();
const loggedIn = accessToken !== '';

Check warning on line 66 in src/App.tsx

View workflow job for this annotation

GitHub Actions / lint

'loggedIn' is assigned a value but never used

const profileMenuItems = useMemo(

Check warning on line 68 in src/App.tsx

View workflow job for this annotation

GitHub Actions / lint

'profileMenuItems' is assigned a value but never used
(): MenuProps['items'] => [
{
key: 'userInfo',
label: (
<div
style={{
display: 'flex',
flexDirection: 'column',
cursor: 'default',
}}
>
<Typography.Text>User name here</Typography.Text>
<Typography.Text>[email protected]</Typography.Text>
</div>
),
},
{
type: 'divider',
},
{
key: 'logout',
label: 'Log out',
onClick: () => logout().then(() => navigate('/')),
},
],
[],

Check warning on line 94 in src/App.tsx

View workflow job for this annotation

GitHub Actions / lint

React Hook useMemo has missing dependencies: 'logout' and 'navigate'. Either include them or remove the dependency array
);

// commenting login UI for now until repositories are merged
// return !loggedIn ? (
// <Login />
// ) : (
return (
<ConfigProvider
theme={{
Expand All @@ -65,23 +111,54 @@
>
<Layout>
{/* Header */}
<Layout.Header style={{ display: 'flex', alignItems: 'center' }}>
<div style={{ marginRight: 24 }} onClick={() => navigate('/')}>
<img src="/uc-logo-reverse.png" height={32} alt="uc-logo-reverse" />
<Layout.Header
style={{
display: 'flex',
alignItems: 'center',
width: '100%',
justifyContent: 'space-between',
}}
>
<div
style={{ display: 'flex', alignItems: 'center', flex: '1 0 auto' }}
>
<div style={{ marginRight: 24 }} onClick={() => navigate('/')}>
<img
src="/uc-logo-reverse.png"
height={32}
alt="uc-logo-reverse"
/>
</div>
<Menu
theme="dark"
mode="horizontal"
defaultSelectedKeys={['catalogs']}
items={[
{
key: 'catalogs',
label: 'Catalogs',
onClick: () => navigate('/'),
},
]}
style={{ flex: 1, minWidth: 0 }}
/>
</div>
<Menu
theme="dark"
mode="horizontal"
defaultSelectedKeys={['catalogs']}
items={[
{
key: 'catalogs',
label: 'Catalogs',
onClick: () => navigate('/'),
},
]}
style={{ flex: 1, minWidth: 0 }}
/>
{/*<div>*/}
{/* <Dropdown*/}
{/* menu={{ items: profileMenuItems }}*/}
{/* trigger={['click']}*/}
{/* placement={'bottomRight'}*/}
{/* >*/}
{/* <Avatar*/}
{/* icon={<UserOutlined />}*/}
{/* style={{*/}
{/* backgroundColor: 'white',*/}
{/* color: 'black',*/}
{/* cursor: 'pointer',*/}
{/* }}*/}
{/* />*/}
{/* </Dropdown>*/}
{/*</div>*/}
</Layout.Header>
{/* Content */}
<Layout.Content
Expand Down Expand Up @@ -118,6 +195,7 @@
</Layout>
</ConfigProvider>
);
// );
}

function App() {
Expand All @@ -128,7 +206,9 @@
return (
<NotificationProvider>
<QueryClientProvider client={queryClient}>
<RouterProvider router={router} fallbackElement={<p>Loading...</p>} />
<AuthProvider>
<RouterProvider router={router} fallbackElement={<p>Loading...</p>} />
</AuthProvider>
</QueryClientProvider>
</NotificationProvider>
);
Expand Down
68 changes: 68 additions & 0 deletions src/components/login/GoogleAuthButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { useCallback, useEffect, useMemo } from 'react';
import { Button } from 'antd';

export default function GoogleAuthButton({
onGoogleSignIn,
}: {
onGoogleSignIn: (credential: string) => void;
}) {
const clientId = useMemo(() => process.env.REACT_APP_GOOGLE_CLIENT_ID, []);

const handleGoogleSignIn = useCallback(
(res: any) => {
if (!res.clientId || !res.credential) return;
onGoogleSignIn(res.credential);
},
[onGoogleSignIn],
);

useEffect(() => {
const url = 'https://accounts.google.com/gsi/client';
const scripts = document.getElementsByTagName('script');
const isGsiScriptLoaded = Array.from(scripts).some(
(script) => script.src === url,
);

if (isGsiScriptLoaded) return;

const initializeGsi = () => {
// Typescript will complain about window.google
// Add types to your `react-app-env.d.ts` or //@ts-ignore it.
if (!(window as any).google || isGsiScriptLoaded) return;

(window as any).google.accounts.id.initialize({
client_id: process.env.REACT_APP_GOOGLE_CLIENT_ID,
callback: handleGoogleSignIn,
});

(window as any).google.accounts.id.renderButton(
document.getElementById('google-client-button'),
{
text: 'continue_with', // customization attributes
width: 240,
theme: 'outline',
},
);
};

const script = document.createElement('script');
script.src = 'https://accounts.google.com/gsi/client';
script.onload = initializeGsi;
script.defer = true;
script.async = true;
script.id = 'google-client-script';
document.querySelector('body')?.appendChild(script);

return () => {
// Cleanup function that runs when component unmounts
(window as any).google?.accounts.id.cancel();
document.getElementById('google-client-script')?.remove();
};
}, [handleGoogleSignIn]);

return (
<>
{clientId && <Button style={{ width: 240 }} id="google-client-button" />}
</>
);
}
Loading
Loading