Authentication

Most of the API needs only your key. The member operations (getMe, getMyCalendar and the selection operations) also need a member token: proof that a particular person has logged in. This guide is for a club site that lets its members log in and see their own details.

Who logs in, and where

The member logs in on the lovebowls login page, which Wix hosts. Your page never shows a password field and never sees a password. The member signs in with the account they already use on lovebowls, and the API answers only for that member's own record in the club the key belongs to.

The sign-in is the standard OAuth authorization code flow with PKCE. The JavaScript SDK does all of it (LovebowlsAuth); you only add a Log in button and a page to return to:

  1. login() sends the browser to the lovebowls login page.
  2. The member signs in. The browser comes back to your redirect URI with a one-time code.
  3. handleRedirect() checks it, exchanges it for a token, and removes the code from the address bar.
  4. LovebowlsClient sends the token as Authorization: Bearer <token> on member calls, and only on those.

See it running in the member example.

What lovebowls sets up for you

Two things you cannot do yourself. Ask lovebowls for both:

Draft clubs

A club that has not been published is a draft, and its data goes only to its own members. Every club read (getClub, listCompetitions, listFixtures, getFixture) answers 404 club_not_found for a draft club, the same as for a club that does not exist, unless the request also carries the member token of a member of that club (Authorization: Bearer <token>). A call that carries a token is answered Cache-Control: private, no-store, and a token Wix refuses is 401 member_token_invalid - the API does not quietly read as a visitor instead. Published clubs are unchanged: no token needed. LovebowlsClient sends the token on these calls whenever a member is logged in.

Tokens

Logout does not revoke tokens

logout() clears the token from the browser and, unless you pass redirect: false, sends the browser through Wix's logout page back to postLogoutUrl (its origin must be allowed on the OAuth client).

This was measured: a Wix logout revokes neither the access token nor the refresh token, and Wix offers no way to revoke one. A copy of a token taken before logout stays valid until it expires (4 hours for an access token). So logging out protects this browser, which is why the SDK drops the tokens locally first. It does not protect against a token someone has already copied. This is the reason for the short lifetime and for refresh tokens being off by default.

Where the token is kept

storageKeptSurvives
"session" (default)sessionStoragea reload; gone when the tab closes
"local"localStorageclosing the browser
"memory"the page onlynothing: lost on reload
your own object{ getItem, setItem, removeItem }whatever it does

Any script on your page can read browser storage, so do not load scripts you do not trust.

Errors

codeStatusMeaningWhat to do
member_token_required401 (SDK: 0)No token was sent, or the SDK holds none (never logged in, or the session ended).Offer login.
member_token_invalid401The token is malformed, expired, revoked or not ours. With a refresh token the SDK retries once; otherwise it clears the session.Offer login.
not_a_member403A valid login, but that person is not a member of this club.Tell the person. Logging in again will not help.
login_failed, state_mismatch0 (SDK only)The sign-in was refused, did not complete, or did not match the request that started it.Start again.

All are described with the others in Errors. Quote the requestId when you ask for help.

Using a member token from a server

If your own server already holds a member token, pass it to the client. There is no LovebowlsAuth in Node, and the client does not renew a token you supply:

import { LovebowlsClient } from "@lovebowls/api";

const lb = new LovebowlsClient({
  apiKey: process.env.LOVEBOWLS_API_KEY,               // a server key
  memberToken: async () => tokenStore.get(userId),     // or a plain string
});
const me = await lb.getMe("CLUB_ID");

On member_token_invalid, get a new token and call again. Treat the token like a password: never log it or put it in a URL.

What the token can do

It identifies the member to the API, and nothing else: the member operations return only that member's own data (see Members), the club is fixed by your key, and the token cannot be used to read another member or another club.