build: switch from yarn to npm to manage js dependencies and move js contents to root

yarn v1 is being deprecated and starts to have some issues

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2023-11-14 17:24:42 +01:00
parent 32055122c3
commit 2e72f6faf4
595 changed files with 12078 additions and 7843 deletions

View File

@@ -0,0 +1,22 @@
import { NavigationGuard } from "vue-router";
import { UserRouteName } from "@/router/user";
import { AUTH_ACCESS_TOKEN } from "@/constants";
import { LoginErrorCode } from "@/types/enums";
export const authGuardIfNeeded: NavigationGuard = async (to, from, next) => {
if (to.meta?.requiredAuth !== true) return next();
// We can't use "currentUser" from apollo here
// because we may not have loaded the user from the local storage yet
if (!localStorage.getItem(AUTH_ACCESS_TOKEN)) {
return next({
name: UserRouteName.LOGIN,
query: {
code: LoginErrorCode.NEED_TO_LOGIN,
redirect: to.fullPath,
},
});
}
return next();
};

View File

@@ -0,0 +1,33 @@
import { IConfig } from "@/types/config.model";
import { ErrorCode } from "@/types/enums";
import { provideApolloClient, useQuery } from "@vue/apollo-composable";
import { NavigationGuard } from "vue-router";
import { CONFIG } from "../../graphql/config";
import { apolloClient } from "../../vue-apollo";
import { ErrorRouteName } from "../error";
export const beforeRegisterGuard: NavigationGuard = async (to, from, next) => {
const { onResult, onError } = provideApolloClient(apolloClient)(() =>
useQuery<{ config: IConfig }>(CONFIG)
);
onResult(({ data }) => {
if (!data) return next();
const { config } = data;
if (!config.registrationsOpen && !config.registrationsAllowlist) {
return next({
name: ErrorRouteName.ERROR,
query: { code: ErrorCode.REGISTRATION_CLOSED },
});
}
return next();
});
onError((err) => {
console.error(err);
return next();
});
return next();
};