Skip to content

Commit d39597d

Browse files
committed
fix: fixed auth0
1 parent a243b4d commit d39597d

File tree

15 files changed

+360
-228
lines changed

15 files changed

+360
-228
lines changed

.vscode/settings.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"cSpell.words": [
3+
"nuxt"
4+
]
5+
}

components/common/header/index.vue

+7-8
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,16 @@
55
</router-link>
66
<breadrumbs />
77
<div class="header-settings">
8-
<span class="link-normal" @click="isAuthenticated ? logout() : login()">
9-
{{ isAuthenticated }}
10-
{{ user }}
11-
{{ isAuthenticated ? 'Sign out' : 'Sign in' }}
12-
</span>
8+
<a class="link-normal" :href="user ? '/api/auth/logout' : '/api/auth/login'">
9+
{{ user ? 'Sign out' : 'Sign in' }}
10+
</a>
1311
</div>
1412
</div>
1513
</template>
1614
<script setup lang="ts">
1715
import Breadrumbs from '@/components/common/breadcrumbs/index.vue'
18-
import { useAuth0 } from '@/composables/auth0';
19-
const { login, isAuthenticated, logout, user } = useAuth0()
20-
const auth = computed(() => { return isAuthenticated })
16+
const user = useUser()
17+
// import { useAuth0 } from '@/composables/auth0';
18+
// const { login, isAuthenticated, logout, user } = useAuth0()
19+
// const auth = computed(() => { return isAuthenticated })
2120
</script>

composables/auth0.js

-44
This file was deleted.

composables/useUser.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { useState } from '#app'
2+
import { User } from '@auth0/auth0-spa-js'
3+
4+
export default function () {
5+
return useState<User>('user', () => null)
6+
}

middleware/watchdog.global.ts

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import useUser from "~~/composables/useUser";
2+
3+
export default defineNuxtRouteMiddleware((to, from) => {
4+
const user = useUser()
5+
const allowedRoutes = ['/', '/login']
6+
if (user.value) {
7+
if (allowedRoutes.includes(to.path)) {
8+
return navigateTo('/private')
9+
}
10+
} else {
11+
if (!allowedRoutes.includes(to.path)) {
12+
return navigateTo('/login')
13+
}
14+
}
15+
})

nuxt.config.ts

+18-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
// https://nuxt.com/docs/api/configuration/nuxt-config
22
// import vue from '@vitejs/plugin-vue'
3+
const {
4+
AUTH0_BASE_URL,
5+
AUTH0_ISSUER_BASE_URL,
6+
AUTH0_CLIENT_ID,
7+
AUTH0_CLIENT_SECRET,
8+
AUTH0_AUDIENCE,
9+
AUTH0_COOKIE_NAME
10+
} = process.env
11+
312
export default defineNuxtConfig({
413
devtools: { enabled: true },
514
// css
@@ -11,7 +20,15 @@ export default defineNuxtConfig({
1120
user: process.env.DBUSERNAME,
1221
pass: process.env.DBPASSWORD,
1322
authSource: process.env.DBAUTHSOURCE,
14-
mainPage: process.env.MAINPAGE
23+
AUTH0_BASE_URL,
24+
AUTH0_ISSUER_BASE_URL,
25+
AUTH0_CLIENT_ID,
26+
AUTH0_CLIENT_SECRET,
27+
AUTH0_AUDIENCE,
28+
AUTH0_COOKIE_NAME,
29+
public: {
30+
AUTH0_COOKIE_NAME
31+
}
1532
},
1633

1734
modules: [

0 commit comments

Comments
 (0)