A demo SvelteKit application backed by Hasura that uses Lucia for authentication.
The implementation done here is not ready for production. It's simply demonstrating how one can get Lucia and Hasura to play well together, but there may be (and probably is) some security concerns that should be addressed when applying this method to your own project.
More often than not, a user would need to be authenticated within your platform to make any requests to your backend and Hasura. Hasura's most popular method of authenticating requests is done via JWT, whereas Lucia Auth uses sessions and cookies, and this is the problem.
As documented on their site, you can either authenticate requests via JWT or via an authentication webhook. In order to authenticate Hasura with Lucia's method of authentication, we will be taking advantage of webhook authentication.
From a high level overview, this is the solution:
src/routes/api/auth/graphql-webhook/+server.ts
).X-Hasura-Role
which can be set to any role you want. This role is used for permissions within Hasura's console.http://localhost:5173/v1/graphql
, which will then forward the request to Hasura's GraphQL
endpoint, which by default is at http://localhost:8080/v1/graphql
.vite.config.ts