Files
front/middleware/auth.global.ts
T
2024-12-20 21:56:37 +01:00

58 lines
1.6 KiB
TypeScript

import { useAuthStore } from "#imports";
const validPaths = ["/login", "/lobby", "/rules", "/test"];
export default defineNuxtRouteMiddleware(async (to, from) => {
const authStore = useAuthStore();
const config = useRuntimeConfig();
// if (to.path == '/') {
// const code = to.query.code
// if (code) {
// if (!Array.isArray(code)) {
// try {
// await oauth2_register_discord(code)
// return navigateTo('/lobby')
// } catch {
// return navigateTo('/login')
// }
// } else {
// return navigateTo('/login')
// }
// }
// return navigateTo("/lobby")
// }
// if (!goStore.discordId) {
// const heron_session = useCookie('heron_session')
// if (!heron_session.value) { return navigateTo('/login') }
// try {
// await heron_cookie_login(heron_session.value)
// if (to.path == '/') {
// return navigateTo("/lobby")
// }
// } catch {
// return navigateTo('/login')
// }
// }
if (to.path.startsWith("/game")) {
return;
}
if (to.path == "/logout") {
// const session = useCookie("heron.session");
// session.value = null;
// return navigateTo("/lobby");
return;
}
if (validPaths.includes(to.path)) {
return;
}
// In a real app you would probably not redirect every route to `/`
// however it is important to check `to.path` before redirecting or you
// might get an infinite redirect loop
if (to.path !== "/") {
return navigateTo("/");
}
return navigateTo("/lobby");
});