convex-auth with sveltekit
Hi Here,
While convex references and examples are react-heavy (react-focused) , i want to ask if anyone has been successful in implementing convex-auth with sveltekit , particularly with session validation in server hooks .
Thanks
2 Replies
Thanks for posting in <#1088161997662724167>.
Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets.
- Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.)
- Use search.convex.dev to search Docs, Stack, and Discord all at once.
- Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI.
- Avoid tagging staff unless specifically instructed.
Thank you!
I used AuthJS with SvelteKit in my recent project based on these two tutorials:
https://stack.convex.dev/nextauth-adapter
https://stack.convex.dev/nextauth
Most of these are not required if you are using Convex Auth, but in both cases you will need your own ConvexAuthProvider Svelte component which is like:
<script lang="ts">
import { variables } from '$lib/variables';
import { setupConvex, useConvexClient } from 'convex-svelte';
let {
token,
children
}: {
children: any;
token: string | undefined | null;
} = $props();
// initialise Convex context
setupConvex(variables.convexUrl);
// set ID token for convex client if available in the session (aka the user is logged in)
$effect.pre(() => {
if (token) {
const client = useConvexClient();
client.setAuth(async () => token);
}
});
</script>
{@render children()}
Convex Adapter for Auth.js (NextAuth) Setup Guide
Learn how to install and configure the Convex adapter for Auth.js as part of getting set up with Convex and Next.js.
Convex with Auth.js (NextAuth)
Learn how to use Auth.js with your Next.js server and Convex backend to build a full-featured authentication system.