Introducing the htmx-supabase-spring-boot-starter v0.3

Introducing the htmx-supabase-spring-boot-starter v0.3

htmx is an awesome library to build interactive web applications directly in HTML, without the javascript headache.

In my htmx project, I wanted to use a hosted authentication provider. I did not want to deal with user credentials myself.

I researched the market and found Supabase which had an interesting offering for free!

  • 50.000 monthly active users

  • Hosted Postgres server with 500 MB storage

This was definitely sufficient for my side projects!

However the Supabase Authentication was built on GoTrue and was not ready to be integrated into my Spring Boot application.

That is why I decided to create the htmx-supabase-spring-boot-starter!

Key features:

  • Supabase Authentication integration

  • Spring Security configuration with application.yaml/properties

  • Role-Based Access Control

  • Basic Authentication

Integrating htmx-supabase-spring-boot-starter

The setup is straightforward ->

Add the Dependency


Configure your application.yaml:

  projectId: yourProjectId
  databasePassword: ${SUPABASE_DATABASE_PW}
  successfulLoginRedirectPage: "/account"
  passwordRecoveryPage: /updatePassword
  unauthenticatedPage: /unauthenticated
  unauthorizedPage: /unauthorizedPage
  sslOnly: false

Add the necessary public paths:

      - "/unauthenticated"
      - "/unauthorized"
      - "/api/user/logout"
      - "/api/user/signup"
      - "/api/user/sendEmailOtp"
      - "/api/user/login"
      - "/api/user/jwt"
      - "/api/user/sendPasswordResetEmail"

Add the javascript snippets that authorize a user after login:

    if (window.location.hash.startsWith("#access_token")) {
        htmx.ajax('POST', '/api/user/jwt', {target: '#body', swap: 'outerHTML'})
            .then(window.location.hash = "")

Now add a signup form:

        <input type="text" name="email"/>
        <input type="password" name="password"/>
    <button hx-post="/api/user/signup">Submit</button>

And a login form:

        <input type="text" name="email"/>
        <input type="password" name="password"/>
    <button hx-post="/api/user/login">Submit</button>

That's it! You now have a secured Spring Boot + htmx application, where a user can register and then log in.

If you want to dive deeper into the configuration, you can check out the README in the GitHub repo: