31 lines
909 B
TypeScript
31 lines
909 B
TypeScript
export default defineNuxtRouteMiddleware(async (to, _from) => {
|
|
const runtimeConfig = useRuntimeConfig()
|
|
|
|
const code = to.query.code;
|
|
if (to.path === "/poll") {
|
|
const { error } = await useFetch(`${runtimeConfig.public.apiBase}/check/${code}`);
|
|
if (error.value && error.value.statusCode !== 200) {
|
|
if(error.value.statusCode == 403){
|
|
return navigateTo({path:"/results", query:to.query});
|
|
}
|
|
throw createError({
|
|
statusCode: error.value.statusCode,
|
|
statusMessage: error.value.statusMessage,
|
|
message: error.value.data.message
|
|
});
|
|
}
|
|
return;
|
|
}
|
|
|
|
if(to.path === "/results"){
|
|
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("/");
|
|
}
|
|
});
|