Hello, I want to integrate Plasmic into an existing Nextjs codebase utilizing Appwrite authentication. Can I pass my Appwrite users and session tokens into Plasmic to use for routing and dynamic data? The authentication system works in the existing codebase, but how do I get it to communicate with Plasmic?
Long live Plasmic.
Hi @a_vaughn
You can register a global context that reads your Appwrite session and exposes the user data through a DataProvider. You can then use $ctx.user in Studio for dynamic text, conditional visibility, etc.
- Protected routes: You can add page metadata (e.g.
requiresAuth) in Page settings, and check it against the Appwrite session in your catch-all page to redirect logged-out users. Something like this
const pageMeta = plasmicData.entryCompMetas[0];
if (pageMeta.metadata?.requiresAuth === "true" && !(await getAppwriteUser(context))) {
return { redirect: { destination: "/login", permanent: false } };
}
- Any other per-user data you fetch from Appwrite in your own code and want to expose to Plasmic, you can do it using code components.
Thanks