feat: add check for email verification requirement and redirect if needed in auth middleware
This commit is contained in:
parent
e95e81112b
commit
dd63095526
1 changed files with 15 additions and 1 deletions
|
@ -2,7 +2,21 @@ export default defineNuxtRouteMiddleware(async (to, from) => {
|
|||
console.log("to.fullPath:", to.fullPath);
|
||||
const loading = useState("loading");
|
||||
const accessToken = useCookie("access_token").value;
|
||||
if (["/login", "/register"].includes(to.path)) {
|
||||
const apiBase = useCookie("api_base").value;
|
||||
const { fetchInstanceStats } = useApi();
|
||||
|
||||
console.log("[AUTH] instance url:", apiBase);
|
||||
if (apiBase && !Object.keys(to.query).includes("special") && to.path != "/verify-email") {
|
||||
const user = await useAuth().getUser();
|
||||
const stats = await fetchInstanceStats(apiBase);
|
||||
console.log("[AUTH] stats:", stats);
|
||||
console.log("[AUTH] email verification check:", user?.email && !user.email_verified && stats.email_verification_required);
|
||||
if (user?.email && !user.email_verified && stats.email_verification_required) {
|
||||
return await navigateTo("/register?special=verify_email");
|
||||
}
|
||||
}
|
||||
|
||||
if (["/login", "/register"].includes(to.path) && !Object.keys(to.query).includes("special")) {
|
||||
console.log("path is login or register");
|
||||
const apiBase = useCookie("api_base");
|
||||
console.log("apiBase gotten:", apiBase.value);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue