+
);
-}
+};
-export default MyApp;
+export default App;
diff --git a/pages/index.tsx b/pages/index.tsx
index 62855153..52375267 100644
--- a/pages/index.tsx
+++ b/pages/index.tsx
@@ -1,9 +1,37 @@
+import React from 'react';
import { css } from '@emotion/core';
import { useTheme } from 'emotion-theming';
+import urlJoin from 'url-join';
+
import defaultTheme from '../components/theme';
+import { getConfig } from '../global/config';
+import { EGO_JWT_KEY } from '../global/utils/constants';
const HomePage = () => {
const theme: typeof defaultTheme = useTheme();
+ const { NEXT_PUBLIC_EGO_API_ROOT, NEXT_PUBLIC_EGO_CLIENT_ID } = getConfig();
+ React.useEffect(() => {
+ const egoLoginUrl = urlJoin(
+ NEXT_PUBLIC_EGO_API_ROOT,
+ `/api/oauth/ego-token?client_id=${NEXT_PUBLIC_EGO_CLIENT_ID}`,
+ );
+ fetch(egoLoginUrl, {
+ credentials: 'include',
+ headers: { accept: '*/*' },
+ body: null,
+ method: 'GET',
+ mode: 'cors',
+ })
+ .then((res) => res.text())
+ .then((egoToken) => {
+ localStorage.setItem(EGO_JWT_KEY, egoToken);
+ redirect(egoToken);
+ })
+ .catch((err) => {
+ console.warn('err: ', err);
+ redirect(null);
+ });
+ });
return (
Date: Thu, 4 Feb 2021 10:18:35 -0500
Subject: [PATCH 02/23] wip ego login
---
components/Root.tsx | 2 +-
global/hooks/useAuthContext.tsx | 19 +++++------
global/utils/pages/index.tsx | 7 +++-
global/utils/pages/types.ts | 1 +
next-env.d.ts | 4 +++
package-lock.json | 47 ++++++++++++++++++++++++---
package.json | 6 +++-
pages/_app.tsx | 39 ++++++++++++++++++++--
pages/index.tsx | 53 +++++++-----------------------
pages/logged-in.tsx | 57 +++++++++++++++++++++++++++++++++
pages/login/index.tsx | 9 +++---
pages/repository/index.tsx | 1 +
url-join.d.ts | 1 -
13 files changed, 180 insertions(+), 66 deletions(-)
create mode 100644 pages/logged-in.tsx
delete mode 100644 url-join.d.ts
diff --git a/components/Root.tsx b/components/Root.tsx
index deb10c9e..079d840b 100644
--- a/components/Root.tsx
+++ b/components/Root.tsx
@@ -4,7 +4,7 @@ import defaultTheme from './theme';
import Head from './Head';
import { AuthProvider } from '../global/hooks/useAuthContext';
-const Root = ({ children, egoJwt }: { children: React.ReactElement; egoJwt: string }) => {
+const Root = ({ children, egoJwt }: { children: React.ReactElement; egoJwt?: string }) => {
return (
<>