Fix : add login page

This commit is contained in:
2024-08-01 15:54:39 +02:00
parent c68446bf25
commit 240ab7e1d4
2 changed files with 17 additions and 20 deletions
+5 -20
View File
@@ -3,24 +3,6 @@ import { useAuthStore } from "#imports";
export default defineNuxtRouteMiddleware(async (to, from) => {
const authStore = useAuthStore();
const config = useRuntimeConfig();
if (to.path == "/login") {
const code = to.query.code;
if (!code) {
return navigateTo(config.public.discordLoginEndpoint, { external: true });
}
if (!Array.isArray(code)) {
try {
await authStore.whoami();
return navigateTo("/lobby");
} catch {
return navigateTo("/login");
}
} else {
return navigateTo("/login");
}
}
// if (to.path == '/') {
// const code = to.query.code
// if (code) {
@@ -51,14 +33,17 @@ export default defineNuxtRouteMiddleware(async (to, from) => {
// return navigateTo('/login')
// }
// }
console.log(to.path)
console.log(to.path);
if (to.path.startsWith("/game")) {
console.log(to.query.id)
console.log(to.query.id);
// if (Array.isArray(to.query.id)) {
// return navigateTo("/lobby");
// }
return;
}
if (to.path == "/login") {
return;
}
if (to.path == "/lobby") {
return;
}
+12
View File
@@ -0,0 +1,12 @@
<script setup lang="ts">
const route = useRoute();
const config = useRuntimeConfig();
const code = route.query.code;
if (!code) {
navigateTo(config.public.discordLoginEndpoint, { external: true });
} else {
navigateTo("/login");
}
</script>