-
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.
- Loading branch information
1 parent
b12ccb0
commit 467a765
Showing
15 changed files
with
245 additions
and
39 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,7 @@ | ||
# Populated by @carto/create-common. | ||
VITE_APP_TITLE="$title" | ||
VITE_CARTO_ACCESS_TOKEN="$accessToken" | ||
|
||
VITE_CARTO_AUTH_ENABLED="$authEnabled" | ||
# VITE_CARTO_AUTH_DOMAIN="$authDomain" | ||
VITE_CARTO_AUTH_CLIENT_ID="$authClientID" |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
23 changes: 12 additions & 11 deletions
23
packages/create-react/src/components/common/ProtectedRoute.tsx
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,25 +1,26 @@ | ||
import { Navigate } from 'react-router-dom'; | ||
// import { useAuth0 } from '@auth0/auth0-react'; | ||
import { RoutePath } from '../../routes'; | ||
import { useAuth0 } from '@auth0/auth0-react'; | ||
import { AppContext } from '../../context'; | ||
import { useContext } from 'react'; | ||
import { useAuth } from '../../hooks/useAuth'; | ||
|
||
export default function ProtectedRoute({ | ||
children, | ||
}: { | ||
children: JSX.Element; | ||
}) { | ||
// TODO(impl): Auth | ||
// const { isAuthenticated, isLoading } = useAuth0(); | ||
useAuth(); | ||
const { isAuthenticated, isLoading } = useAuth0(); | ||
const { oauth, accessToken } = useContext(AppContext); | ||
|
||
// if (!initialState.oauth) { | ||
// return children; | ||
// } | ||
|
||
const authenticated = true; //notAuthenticated = !isLoading && !isAuthenticated && !accessToken; | ||
if (!oauth.enabled) { | ||
return children; | ||
} | ||
|
||
if (!authenticated) { | ||
if (!isLoading && !isAuthenticated && !accessToken) { | ||
return <Navigate to={RoutePath.LOGIN} />; | ||
} | ||
|
||
return children; | ||
// return !!accessToken ? children : null; | ||
return accessToken ? children : null; | ||
} |
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,3 +1,19 @@ | ||
import { useAuth0 } from '@auth0/auth0-react'; | ||
import { useContext } from 'react'; | ||
import { AppContext } from '../../context'; | ||
|
||
export default function Login() { | ||
return <h1>Login</h1>; | ||
const { title, logo } = useContext(AppContext); | ||
const { loginWithRedirect } = useAuth0(); | ||
return ( | ||
<main className="login"> | ||
{logo && <img className="login-logo" src={logo.src} alt={logo.alt} />} | ||
<h1 className="title">{title}</h1> | ||
<p className="subtitle">Discover the power of developing with React</p> | ||
<button className="body1" onClick={() => loginWithRedirect()}> | ||
Login with CARTO | ||
</button> | ||
<p className="caption">Use your CARTO credentials</p> | ||
</main> | ||
); | ||
} |
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 { useAuth0 } from '@auth0/auth0-react'; | ||
|
||
export default function Logout() { | ||
const { logout } = useAuth0(); | ||
|
||
logout(); | ||
|
||
return <p>Logging out…</p>; | ||
} |
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
Oops, something went wrong.