Skip to content

supabase/gotrue-js

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

Adds a new algorithm that automatically refreshes the user's session.

Problems with the previous algorithm:
- Complex retry logic 
- Difficult to read and reason about quickly
- Used in-memory state while session state is not in memory -- local
storage, cookies, etc.
- Could produce endless retries
- Not multi-tab resilient -- performed refresh from all open tabs at
once
- Not clock-skew resilient

New algorithm:
- Runs every 10 seconds (`AUTO_REFRESH_TICK_DURATION`) -- tick
- Each tick checks the session from the proper storage medium (not
possible to have unsynced state)
- If the expiration is within 3 ticks (`AUTO_REFRESH_TICK_THRESHOLD`) a
refresh is attempted
- If a refresh is not successful, another one will be attempted on the
next tick
- A failing refresh due to network errors will be retried exponentially
but up to a maximum of 10 seconds
- Auto refresh runs only on visible tabs, not on hidden tabs

Co-authored-by: Joel Lee <lee.yi.jie.joel@gmail.com>
013afae

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

gotrue-js

An isomorphic JavaScript client library for the GoTrue API.

Docs

Quick start

Install

npm install --save @supabase/gotrue-js

Usage

import { GoTrueClient } from '@supabase/gotrue-js'

const GOTRUE_URL = 'http://localhost:9999'

const auth = new GoTrueClient({ url: GOTRUE_URL })

Custom fetch implementation

gotrue-js uses the cross-fetch library to make HTTP requests, but an alternative fetch implementation can be provided as an option. This is most useful in environments where cross-fetch is not compatible, for instance Cloudflare Workers:

import { GoTrueClient } from '@supabase/gotrue-js'

const GOTRUE_URL = 'http://localhost:9999'

const auth = new GoTrueClient({ url: GOTRUE_URL, fetch: fetch })

Sponsors

We are building the features of Firebase using enterprise-grade, open source products. We support existing communities wherever possible, and if the products don’t exist we build them and open source them ourselves.

New Sponsor

Watch this repo