-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added root App component with silent auth
- Loading branch information
Showing
10 changed files
with
71 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
{ | ||
"files": { | ||
"main.css": "./static/css/main.71786728.css", | ||
"main.js": "./static/js/main.dd254ed8.js", | ||
"main.js": "./static/js/main.e34b8f99.js", | ||
"static/media/isbn_mod_bg.wasm": "./static/media/isbn_mod_bg.415d4eff989481533d43.wasm", | ||
"static/media/buy.svg": "./static/media/buy.a0ebbd4b83f7c8afd5d9.svg", | ||
"static/media/icomoon.woff": "./static/media/icomoon.25908258b2a9c6e6da52.woff", | ||
"index.html": "./index.html", | ||
"static/media/about.svg": "./static/media/about.472d9c94914ce88e8d8f.svg", | ||
"static/media/borrow.svg": "./static/media/borrow.f8356d8f6c1fc40fa23b.svg", | ||
"main.71786728.css.map": "./static/css/main.71786728.css.map", | ||
"main.dd254ed8.js.map": "./static/js/main.dd254ed8.js.map" | ||
"main.e34b8f99.js.map": "./static/js/main.e34b8f99.js.map" | ||
}, | ||
"entrypoints": [ | ||
"static/css/main.71786728.css", | ||
"static/js/main.dd254ed8.js" | ||
"static/js/main.e34b8f99.js" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
<!doctype html><html lang="en"><head prefix="og: http://ogp.me/ns#"><meta charset="utf-8"/><meta http-equiv="x-ua-compatible" content="ie=edge"><meta name="referrer" content="no-referrer"/><meta name="theme-color" content="#ffffff"/><meta name="viewport" content="width=device-width,initial-scale=1"/><title>📖📚📚</title><meta name="description" content="A pocket assistant for keen readers: find more information about the book or the author online, borrow it from your local library, buy, sell or share."><meta property="og:title" content="Scan ISBN to record or share a book"/><meta property="og:description" content="A pocket assistant for keen readers: find more information about the book or the author online, borrow it from your local library, buy, sell or share."><meta property="og:site_name" content="Bookworm Food"><meta property="og:type" content="website"><meta property="og:url" content="https://bookwormfood.com"><meta property="og:image" itemprop="image" content="http://bookwormfood.com/img/og-image-400.png"/><meta property="og:image:secure_url" itemprop="image" content="https://bookwormfood.com/img/og-image-400.png"><meta property="og:image:width" content="400"><meta property="og:image:height" content="400"><meta name="twitter:card" content="summary"/><meta name="twitter:title" content="Scan ISBN to record or share a book"/><meta name="twitter:description" content="A pocket assistant for keen readers: find more information about the book or the author online, borrow it from your local library, buy, sell or share."/><meta name="twitter:image" content="https://bookwormfood.com/img/og-image-400.png"/><link rel="apple-touch-icon" sizes="180x180" href="/img/apple-touch-icon.png"/><link rel="icon" type="image/png" sizes="32x32" href="/img/favicon-32x32.png"><link rel="icon" type="image/png" sizes="16x16" href="/img/favicon-16x16.png"><link rel="preconnect" href="https://fonts.googleapis.com"><link rel="preconnect" href="https://fonts.gstatic.com" crossorigin><link href="https://fonts.googleapis.com/css2?family=Amatic+SC:wght@400;700&display=swap" rel="stylesheet"><link href="https://fonts.googleapis.com/css2?family=News+Cycle:wght@400;700&display=swap" rel="stylesheet"><script defer="defer" src="/static/js/main.dd254ed8.js"></script><link href="/static/css/main.71786728.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="app"></div></body></html> | ||
<!doctype html><html lang="en"><head prefix="og: http://ogp.me/ns#"><meta charset="utf-8"/><meta http-equiv="x-ua-compatible" content="ie=edge"><meta name="referrer" content="no-referrer"/><meta name="theme-color" content="#ffffff"/><meta name="viewport" content="width=device-width,initial-scale=1"/><title>📖📚📚</title><meta name="description" content="A pocket assistant for keen readers: find more information about the book or the author online, borrow it from your local library, buy, sell or share."><meta property="og:title" content="Scan ISBN to record or share a book"/><meta property="og:description" content="A pocket assistant for keen readers: find more information about the book or the author online, borrow it from your local library, buy, sell or share."><meta property="og:site_name" content="Bookworm Food"><meta property="og:type" content="website"><meta property="og:url" content="https://bookwormfood.com"><meta property="og:image" itemprop="image" content="http://bookwormfood.com/img/og-image-400.png"/><meta property="og:image:secure_url" itemprop="image" content="https://bookwormfood.com/img/og-image-400.png"><meta property="og:image:width" content="400"><meta property="og:image:height" content="400"><meta name="twitter:card" content="summary"/><meta name="twitter:title" content="Scan ISBN to record or share a book"/><meta name="twitter:description" content="A pocket assistant for keen readers: find more information about the book or the author online, borrow it from your local library, buy, sell or share."/><meta name="twitter:image" content="https://bookwormfood.com/img/og-image-400.png"/><link rel="apple-touch-icon" sizes="180x180" href="/img/apple-touch-icon.png"/><link rel="icon" type="image/png" sizes="32x32" href="/img/favicon-32x32.png"><link rel="icon" type="image/png" sizes="16x16" href="/img/favicon-16x16.png"><link rel="preconnect" href="https://fonts.googleapis.com"><link rel="preconnect" href="https://fonts.gstatic.com" crossorigin><link href="https://fonts.googleapis.com/css2?family=Amatic+SC:wght@400;700&display=swap" rel="stylesheet"><link href="https://fonts.googleapis.com/css2?family=News+Cycle:wght@400;700&display=swap" rel="stylesheet"><script defer="defer" src="/static/js/main.e34b8f99.js"></script><link href="/static/css/main.71786728.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="app"></div></body></html> |
This file was deleted.
Oops, something went wrong.
6 changes: 3 additions & 3 deletions
6
build/static/js/main.dd254ed8.js → build/static/js/main.e34b8f99.js
Large diffs are not rendered by default.
Oops, something went wrong.
File renamed without changes.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { useEffect } from "react"; | ||
import { useLocation, Outlet } from "react-router-dom"; | ||
import { useAuth0 } from '@auth0/auth0-react' | ||
import { LAST_AUTH_TIMESTAMP } from "./bookDetails.js"; | ||
|
||
export default function App() { | ||
|
||
const location = useLocation(); | ||
const { isAuthenticated, isLoading, loginWithRedirect, getAccessTokenSilently } = useAuth0(); | ||
|
||
useEffect(() => { | ||
|
||
console.log(`App load/auth: ${isLoading}/${isAuthenticated}`); | ||
|
||
// save auth details in the localStorage | ||
if (!isLoading) { | ||
if (isAuthenticated) { | ||
localStorage.setItem(LAST_AUTH_TIMESTAMP, Date.now()); | ||
console.log("Auth status updated in LS"); | ||
} | ||
else { | ||
console.log("Not authenticated"); | ||
|
||
(async () => { | ||
|
||
// log in the user if was logged in before | ||
const lastAuth = localStorage.getItem(LAST_AUTH_TIMESTAMP); | ||
console.log(`Last auth/auth'd: ${lastAuth}/${isAuthenticated}`); | ||
if (lastAuth && !isAuthenticated) { | ||
|
||
console.log("User was logged in before, logging in again"); | ||
try { | ||
const accessToken = await getAccessTokenSilently(); | ||
console.log(`Access token: ${accessToken}`); | ||
} catch (e) { | ||
console.log(`Error getting access token: ${e}`); | ||
await loginWithRedirect({ | ||
appState: { | ||
returnTo: window.location.pathname, | ||
}, | ||
}) | ||
} | ||
} | ||
})(); | ||
} | ||
} | ||
|
||
}, [isLoading, isAuthenticated]); | ||
|
||
return ( | ||
<div className="main"> | ||
<Outlet /> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters