- 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.
49 lines
1.3 KiB
TypeScript
49 lines
1.3 KiB
TypeScript
import { createAuth0 } from "@auth0/auth0-vue";
|
|
import { defineNuxtPlugin, useRuntimeConfig } from "nuxt/app";
|
|
|
|
declare module "@auth0/auth0-vue" {
|
|
interface AppState {
|
|
target?: string;
|
|
}
|
|
}
|
|
|
|
export default defineNuxtPlugin((nuxtApp) => {
|
|
const config = useRuntimeConfig();
|
|
const auth0Config = config.public.auth0;
|
|
|
|
if (!auth0Config?.domain || !auth0Config?.clientId) {
|
|
if (process.dev) {
|
|
console.warn(
|
|
"Auth0 configuration is incomplete. Set AUTH0_DOMAIN and AUTH0_CLIENT_ID in your environment."
|
|
);
|
|
}
|
|
return;
|
|
}
|
|
|
|
const redirectUri = auth0Config.redirectUri ?? `${auth0Config.baseUrl}/auth/callback`;
|
|
|
|
nuxtApp.vueApp.use(
|
|
createAuth0({
|
|
domain: auth0Config.domain,
|
|
clientId: auth0Config.clientId,
|
|
authorizationParams: {
|
|
redirect_uri: redirectUri,
|
|
audience: auth0Config.audience || undefined,
|
|
scope: auth0Config.scope,
|
|
},
|
|
cacheLocation: "localstorage",
|
|
useRefreshTokens: true,
|
|
onRedirectCallback: (appState) => {
|
|
const targetPath = appState?.target ?? "/";
|
|
if (nuxtApp.$router) {
|
|
nuxtApp.$router.replace(targetPath).catch(() => {
|
|
window.location.assign(targetPath);
|
|
});
|
|
} else {
|
|
window.location.assign(targetPath);
|
|
}
|
|
},
|
|
})
|
|
);
|
|
});
|