Hi, has anyone tried using SuperTokens with HTMX? If so, do you have any guidance or advice?
z
Hi, has anyone tried using SuperTokens with HTMX? If so, do you have any guidance or advice?
r
hey @zanderpyle i don't think anyone has, but, maybe following our custom UI guide helps?
z
Yes, that's what I've been doing so far. Seems to be going well, but still working on putting everything together.
r
Sounds good
z
The thing is I'm also using Fiber. So I'm having to also figure out how to make ST work with their Middleware
The following ended up working for me, although I'm unaware of any potential performance implications:
Copy code
app.Use(adaptor.HTTPMiddleware(func(handler http.Handler) http.Handler {
        return supertokens.Middleware(handler)
    }))
Still working through the docs, but I assume this middleware will allow me reject unauthorized requests. Although how to indicate which paths require auth and which don't isn't clear to me yet.
r
the supertokens.Middleware doesn't do session verification. It only exposes the APIs to the frontend like sign in, sign up etc
z
Yes, session verification was a bit tricky, but here's how I got it working:
Copy code
func setupApi(app *fiber.App) {
    api := app.Group("/api")
    api.Use(func(c *fiber.Ctx) error {
        return adaptor.HTTPHandlerFunc(func(w http.ResponseWriter, r *http.Request) {
            session.VerifySession(nil, func(w http.ResponseWriter, r *http.Request) {
                adaptor.CopyContextToFiberContext(r.Context(), c.Context())
                log.Println("Session verified")
                err := c.Next()
                if err != nil {
                    log.Println("Error in session verification middleware chain", err)
                }
            })(w, r)
        })(c)
    })
11 Views