-
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
6a35943
commit 15a0e08
Showing
17 changed files
with
237 additions
and
54 deletions.
There are no files selected for viewing
11 changes: 0 additions & 11 deletions
11
packages/create-react/src/components/common/LazyLoadComponent.tsx
This file was deleted.
Oops, something went wrong.
11 changes: 0 additions & 11 deletions
11
packages/create-react/src/components/common/LazyLoadRoute.tsx
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,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" |
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,7 +1,5 @@ | ||
<script setup lang="ts"> | ||
import AppLayout from './components/common/AppLayout.vue'; | ||
</script> | ||
<script setup lang="ts"></script> | ||
|
||
<template> | ||
<AppLayout></AppLayout> | ||
<RouterView /> | ||
</template> |
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
30 changes: 30 additions & 0 deletions
30
packages/create-vue/src/components/common/ProtectedRoute.vue
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,30 @@ | ||
<script setup lang="ts"> | ||
import { effect } from 'vue'; | ||
import AppLayout from './AppLayout.vue'; | ||
import { useAuth0 } from '@auth0/auth0-vue'; | ||
import { context } from '../../context'; | ||
import { router, RoutePath } from '../../routes'; | ||
import { useAuth } from '../../hooks/useAuth'; | ||
useAuth(); | ||
const { isAuthenticated, isLoading } = useAuth0(); | ||
effect(() => { | ||
if ( | ||
context.oauth.enabled && | ||
!context.accessToken && | ||
!isLoading.value && | ||
!isAuthenticated.value | ||
) { | ||
router.replace(RoutePath.LOGIN); | ||
} | ||
}); | ||
</script> | ||
|
||
<template> | ||
<template v-if="!context.oauth.enabled || context.accessToken"> | ||
<AppLayout> | ||
<slot /> | ||
</AppLayout> | ||
</template> | ||
</template> |
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,22 @@ | ||
<script setup lang="ts"> | ||
import { useAuth0 } from '@auth0/auth0-vue'; | ||
import { context } from '../../context'; | ||
const { loginWithRedirect } = useAuth0(); | ||
</script> | ||
|
||
<template> | ||
<main class="login"> | ||
<img | ||
v-if="context.logo" | ||
class="login-logo" | ||
:src="context.logo.src" | ||
:alt="context.logo.alt" | ||
/> | ||
<h1 class="title">{{ context.title }}</h1> | ||
<p class="subtitle">Discover the power of developing with React</p> | ||
<button class="body1" @click="() => loginWithRedirect()"> | ||
Login with CARTO | ||
</button> | ||
<p class="caption">Use your CARTO credentials</p> | ||
</main> | ||
</template> |
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 @@ | ||
<script setup lang="ts"> | ||
import { useAuth0 } from '@auth0/auth0-vue'; | ||
const { logout } = useAuth0(); | ||
logout(); | ||
</script> | ||
|
||
<template> | ||
<p>Logging out…</p> | ||
</template> |
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,3 @@ | ||
<template> | ||
<h1>Not Found</h1> | ||
</template> |
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,47 @@ | ||
import { useAuth0 } from '@auth0/auth0-vue'; | ||
import { useRoute } from 'vue-router'; | ||
import { context } from '../context'; | ||
import { computed, effect } from 'vue'; | ||
|
||
const FORCE_LOGIN_PARAM = 'forceLogin'; | ||
|
||
export function useAuth() { | ||
const route = useRoute(); | ||
const { | ||
isAuthenticated, | ||
getAccessTokenSilently, | ||
user, | ||
loginWithRedirect, | ||
isLoading, | ||
} = useAuth0(); | ||
|
||
const organizationId = context.oauth.organizationId || ''; | ||
const namespace = context.oauth.namespace; | ||
|
||
const userMetadata = computed(() => { | ||
return user.value?.[`${namespace}user_metadata`]; | ||
}); | ||
|
||
const redirectAccountUri = computed(() => { | ||
return organizationId | ||
? `${context.accountsUrl}sso/${organizationId}` | ||
: context.accountsUrl; | ||
}); | ||
|
||
effect(async () => { | ||
if (route.query[FORCE_LOGIN_PARAM]) { | ||
// if FORCE_LOGIN_PARAM is set a relogin is required to refresh userMetadata | ||
loginWithRedirect(); | ||
} else if (isAuthenticated.value && userMetadata.value) { | ||
context.accessToken = await getAccessTokenSilently(); | ||
} else if (isAuthenticated.value && !isLoading.value) { | ||
// No organizations associated with the user, we need to redirect to app.carto.com to complete the signup process | ||
const searchParams = new URLSearchParams({ | ||
redirectUri: `${window.location.origin}?${FORCE_LOGIN_PARAM}=true`, | ||
}); | ||
window.location.href = `${redirectAccountUri.value}?${searchParams}`; | ||
} | ||
}); | ||
|
||
return; | ||
} |
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,6 +1,30 @@ | ||
import { createApp } from 'vue'; | ||
import { createApp, Plugin } from 'vue'; | ||
import '@carto/create-common/style.css'; | ||
import App from './App.vue'; | ||
import { router } from './routes'; | ||
import { context } from './context'; | ||
import { createAuth0 } from '@auth0/auth0-vue'; | ||
|
||
createApp(App).use(router).mount('#root'); | ||
const app = createApp(App); | ||
|
||
app.use(router); | ||
|
||
if (context.oauth.enabled) { | ||
app.use( | ||
createAuth0({ | ||
domain: context.oauth.domain, | ||
clientId: context.oauth.clientId!, | ||
cacheLocation: 'localstorage', | ||
authorizationParams: { | ||
audience: context.oauth.audience, | ||
organization: context.oauth.organizationId, | ||
redirect_uri: window.location.origin, | ||
scope: context.oauth.scopes.join(' '), | ||
}, | ||
}) as unknown as Plugin<[]>, | ||
); | ||
} | ||
|
||
app.mount('#root'); | ||
|
||
document.title = context.title; |
Oops, something went wrong.