-
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.
Better session handling an dless flickering
- Loading branch information
Showing
12 changed files
with
145 additions
and
94 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
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 was deleted.
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
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,20 +1,22 @@ | ||
import {useAuth} from "./AuthContext.tsx"; | ||
import {useNavigate} from "react-router-dom"; | ||
import {useEffect} from "react"; | ||
import Spinner from "./Spinner.tsx"; | ||
|
||
function LoginCallback() { | ||
const auth = useAuth(); | ||
const navigate = useNavigate(); | ||
auth.loginCallback().then(() => { | ||
|
||
useEffect(() => { | ||
auth.loginCallback().then(() => { | ||
navigate("/", {replace: true}); | ||
} | ||
).catch( | ||
() => { | ||
}).catch(() => { | ||
console.error("Login callback failed"); | ||
navigate("/login", {replace: true}); | ||
} | ||
); | ||
return <div> | ||
<p>Logging in…</p> | ||
</div>; | ||
}); | ||
}); | ||
|
||
return <Spinner size="lg"/>; | ||
} | ||
|
||
export default LoginCallback; |
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,27 @@ | ||
import {useAuth} from "./AuthContext.tsx"; | ||
import {useLocation, useNavigate} from "react-router-dom"; | ||
import {useEffect} from "react"; | ||
|
||
function NotFound() { | ||
const auth = useAuth(); | ||
const navigate = useNavigate(); | ||
const location = useLocation(); | ||
|
||
useEffect(() => { | ||
if (auth.user === null) { | ||
navigate("/login", {replace: true, state: {from: location}}); | ||
} | ||
}, [auth, navigate, location]); | ||
|
||
if (auth.user === undefined) { | ||
// avoids flickering | ||
return <div></div> | ||
} | ||
|
||
return <div> | ||
<h1>404</h1> | ||
<p>Page not found</p> | ||
</div> | ||
} | ||
|
||
export default NotFound |
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,10 +1,11 @@ | ||
import {useAuth} from "./AuthContext.tsx"; | ||
import {Navigate} from "react-router-dom"; | ||
import {Navigate, useLocation} from "react-router-dom"; | ||
|
||
function RequireAuth({children}: { children: React.ReactNode }) { | ||
const auth = useAuth(); | ||
const location = useLocation(); | ||
const notLoggedIn = auth.user === undefined || auth.user === null; | ||
return notLoggedIn ? <Navigate to="/login" replace/> : children; | ||
return notLoggedIn ? <Navigate to="/login" replace state={{from: location}}/> : children; | ||
} | ||
|
||
export default RequireAuth |
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,33 @@ | ||
.spinner { | ||
border: 0.2em solid #aaa; | ||
border-bottom-color: transparent; | ||
border-radius: 50%; | ||
display: inline-block; | ||
box-sizing: border-box; | ||
animation: rotation 1s cubic-bezier(.62, .27, .5, .75) infinite; | ||
} | ||
|
||
@keyframes rotation { | ||
0% { | ||
transform: rotate(0deg); | ||
} | ||
100% { | ||
transform: rotate(360deg); | ||
} | ||
} | ||
|
||
.spinner.spinner-sm { | ||
width: 0.5em; | ||
height: 0.5em; | ||
} | ||
|
||
.spinner.spinner-md { | ||
width: 1em; | ||
height: 1em; | ||
} | ||
|
||
.spinner.spinner-lg { | ||
width: 4em; | ||
height: 4em; | ||
border-width: 0.7em; | ||
} |
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,9 @@ | ||
import "./Spinner.css"; | ||
|
||
function Spinner({size}: { size?: "sm" | "md" | "lg" }) { | ||
size = size || "md"; | ||
return <div className={`spinner spinner-${size}`}> | ||
</div>; | ||
} | ||
|
||
export default Spinner; |
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 |
---|---|---|
|
@@ -5,6 +5,7 @@ import App from './App.tsx' | |
|
||
import * as Sentry from "@sentry/react"; | ||
import {BrowserRouter} from "react-router-dom"; | ||
import {AuthProvider} from "./AuthContext.tsx"; | ||
|
||
Sentry.init({ | ||
dsn: "https://[email protected]/6", | ||
|
@@ -15,7 +16,9 @@ Sentry.init({ | |
createRoot(document.getElementById('root')!).render( | ||
<StrictMode> | ||
<BrowserRouter> | ||
<App/> | ||
<AuthProvider> | ||
<App/> | ||
</AuthProvider> | ||
</BrowserRouter> | ||
</StrictMode>, | ||
) |