-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from barbalex/auth
Auth
- Loading branch information
Showing
15 changed files
with
186 additions
and
182 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 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,8 @@ | ||
import { CorbadoAuth } from '@corbado/react' | ||
|
||
export const Auth = () => ( | ||
<CorbadoAuth | ||
onLoggedIn={() => console.log('hi')} | ||
customerSupportEmail="[email protected]" | ||
/> | ||
) |
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
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,21 +1,17 @@ | ||
import { useCorbadoSession } from '@corbado/react' | ||
import { useLocation, Navigate } from 'react-router-dom' | ||
import { memo } from 'react' | ||
import { useCorbado } from '@corbado/react' | ||
import { Loading } from './shared/Loading' | ||
|
||
// https://www.robinwieruch.de/react-router-authentication/ | ||
export const ProtectedRoute = ({ children }) => { | ||
const { loading, isAuthenticated, user } = useCorbadoSession() | ||
const location = useLocation() | ||
import { Auth } from './Auth' | ||
|
||
// console.warn('ProtectedRoute', { loading, isAuthenticated, user }) | ||
// https://www.robinwieruch.de/react-router-authentication/ | ||
export const ProtectedRoute = memo(({ children }) => { | ||
const { loading, isAuthenticated } = useCorbado() | ||
// console.log('hello ProtectedRoute', { loading, isAuthenticated }) | ||
|
||
if (loading) { | ||
return <Loading label="Authenticating" /> | ||
} | ||
if (loading) return <Loading label="Authenticating" /> | ||
|
||
if (!isAuthenticated || !user) { | ||
return <Navigate to="/auth" replace state={{ from: location }} /> | ||
} | ||
if (!isAuthenticated) return <Auth /> | ||
|
||
return children | ||
} | ||
}) |
Oops, something went wrong.