πŸ›‘οΈ Custom Auth

Supabase Custom Auth Element

The Supabase Custom Auth Element allows you to authenticate with Supabase using custom JWT tokens rather than the standard authentication flow. This is particularly useful for integrating with external authentication systems or implementing custom authentication logic.
Image without caption

Element Fields:

Title
Description
Type
Token
Custom token that you have generated using the "Generate JWT" server-side action or on your own. This token (JWT) must have been signed using the Supabase JWT secret.
Text
Expiry soon event (in seconds)
The plugin will automatically trigger the event "JWT expires soon" when the JWT is about to expire. You can use this event to start a workflow that generates a new token for your user. The default value is 10 seconds.
Number
Realtime events per second
Rate limiting. The default is 10, which means that the client can send one event every 100 milliseconds.
Number
JSON headers
Optional JSON headers for initializing the client.
Text
Enable retry?
Enables the retry mechanism for failed network requests. If set to true, the plugin will attempt to retry the request upon encountering client-side network errors.
Boolean
Max retries
The maximum number of retry attempts after a failed request. If not provided, it defaults to 3 retries.
Number
Initial delay (in ms)
The initial delay in milliseconds before the first retry attempt. Subsequent retries will use exponential backoff.
Number

Exposed States:

Name
Description
Type
Is token valid?
Indicating if the token is currently valid.
Boolean
Status code
Error code if the token is invalid.
Number
Status message
Error slug if the token is invalid.
Text
Token
The current token.
Text
Audience
The audience claim from the JWT token.
Text
Role
The role claim from the JWT token.
Text
Subject
The subject claim from the JWT token.
Text
Issuer
The issuer claim from the JWT token.
Text
Email
The email claim from the JWT token.
Text
Expiration time (timestamp)
The expiration timestamp from the JWT token.
Number
Issued at time (timestamp)
The issued at timestamp from the JWT token.
Number
Expiration time (date)
The expiration date from the JWT token.
Date
Issued at time (date)
The issued at date from the JWT token.
Date

Element Events:

Name
Description
Token valid
Triggered when the token is validated successfully.
Token invalid
Triggered when the token is found to be invalid.
Token expires soon
Triggered when the token is about to expire soon.
Supabase is loaded
Triggered when the Supabase client is initialized and ready.
This element works in conjunction with the "Generate JWT (Custom auth)" server-side action that allows you to create custom JWT tokens. The workflow typically involves:
  1. Authenticating the user through your custom logic
  1. Generating a JWT token with the appropriate claims (subject, role, expiration, etc.)
  1. Setting the token in the Supabase Custom Auth element
  1. Handling token expiration by listening to the "Token expires soon" event and refreshing the token before it expires
Custom auth is particularly useful for:
  • Integrating with existing authentication systems
  • Implementing custom authentication flows
  • Creating machine-to-machine authentication
  • Supporting authentication methods not natively provided by Supabase
  • Implementing role-based access control with custom roles
When using custom auth, you still have access to all the other Supabase features (Database, Storage, Edge Functions, Realtime) with the permissions defined by the role specified in your JWT token.