- Implemented `useDesignPersistence` composable for managing design records. - Enhanced `useSlipmatDesigner` to support loading designs from JSON. - Created global authentication middleware for route protection. - Added Supabase client plugin for database interactions. - Developed API endpoints for fetching, saving, and retrieving designs. - Introduced utility functions for Auth0 token verification and Supabase client retrieval. - Updated Nuxt configuration to include Auth0 and Supabase environment variables. - Added necessary dependencies for Auth0 and Supabase. - Enhanced TypeScript configuration for improved type support.
45 lines
836 B
TypeScript
45 lines
836 B
TypeScript
import { useAuth0 } from "@auth0/auth0-vue";
|
|
import { watch } from "vue";
|
|
import { abortNavigation } from "#app";
|
|
|
|
const waitUntilLoaded = async (isLoading: { value: boolean }) => {
|
|
if (!isLoading.value) {
|
|
return;
|
|
}
|
|
|
|
await new Promise<void>((resolve) => {
|
|
const stop = watch(
|
|
() => isLoading.value,
|
|
(value) => {
|
|
if (!value) {
|
|
stop();
|
|
resolve();
|
|
}
|
|
}
|
|
);
|
|
});
|
|
};
|
|
|
|
export default defineNuxtRouteMiddleware(async (to) => {
|
|
if (import.meta.server) {
|
|
return;
|
|
}
|
|
|
|
if (to.path.startsWith("/auth/callback")) {
|
|
return;
|
|
}
|
|
|
|
const auth0 = useAuth0();
|
|
await waitUntilLoaded(auth0.isLoading);
|
|
|
|
if (auth0.isAuthenticated.value) {
|
|
return;
|
|
}
|
|
|
|
await auth0.loginWithRedirect({
|
|
appState: { target: to.fullPath },
|
|
});
|
|
|
|
return abortNavigation();
|
|
});
|