mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-11-30 15:44:37 -05:00
feat: Remove backend cookie and use frontend for auth (#6601)
This commit is contained in:
@@ -1,3 +1,2 @@
|
||||
export { useAppInfo } from "./use-app-info";
|
||||
export { useStaticRoutes } from "./static-routes";
|
||||
export { useAdminApi, usePublicApi, usePublicExploreApi, useUserApi } from "./api-client";
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
import type { AppInfo } from "~/lib/api/types/admin";
|
||||
|
||||
export function useAppInfo(): Ref<AppInfo | null> {
|
||||
const i18n = useI18n();
|
||||
const { $axios } = useNuxtApp();
|
||||
$axios.defaults.headers.common["Accept-Language"] = i18n.locale.value;
|
||||
|
||||
const { data: appInfo } = useAsyncData("app-info", async () => {
|
||||
const data = await $axios.get<AppInfo>("/api/app/about");
|
||||
return data.data;
|
||||
});
|
||||
|
||||
return appInfo;
|
||||
}
|
||||
@@ -5,9 +5,9 @@ const userRatings = ref<UserRatingSummary[]>([]);
|
||||
const loading = ref(false);
|
||||
const ready = ref(false);
|
||||
|
||||
const $auth = useMealieAuth();
|
||||
|
||||
export const useUserSelfRatings = function () {
|
||||
const $auth = useMealieAuth();
|
||||
|
||||
async function refreshUserRatings() {
|
||||
if (!$auth.user.value || loading.value) {
|
||||
return;
|
||||
|
||||
@@ -23,13 +23,15 @@ const authUser = ref<UserOut | null>(null);
|
||||
const authStatus = ref<"loading" | "authenticated" | "unauthenticated">("loading");
|
||||
|
||||
export const useAuthBackend = function (): AuthState {
|
||||
const { $axios } = useNuxtApp();
|
||||
const { $appInfo, $axios } = useNuxtApp();
|
||||
const router = useRouter();
|
||||
|
||||
const runtimeConfig = useRuntimeConfig();
|
||||
const tokenTimeHours = Number(runtimeConfig.public.TOKEN_TIME) || 48;
|
||||
const tokenName = runtimeConfig.public.AUTH_TOKEN;
|
||||
const tokenCookie = useCookie(tokenName, { maxAge: tokenTimeHours * 60 * 60 });
|
||||
const tokenCookie = useCookie(tokenName, {
|
||||
maxAge: $appInfo.tokenTime * 60 * 60,
|
||||
secure: $appInfo.production && window?.location?.protocol === "https:",
|
||||
});
|
||||
|
||||
function setToken(token: string | null) {
|
||||
tokenCookie.value = token;
|
||||
|
||||
Reference in New Issue
Block a user