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:
login()sends the browser to the lovebowls login page.- The member signs in. The browser comes back to your redirect URI with a one-time code.
handleRedirect()checks it, exchanges it for a token, and removes the code from the address bar.LovebowlsClientsends the token asAuthorization: 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:
- The OAuth client id. It is public: it travels in the login URL, so it may sit in your page.
- Your redirect URI on the client's list. It must match exactly (scheme, host, path, trailing
slash), and every club site needs its own entry, for example
https://www.example-bowls.org/members/. Anything else is refused at the login page. The page you give is the page that callshandleRedirect().
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
- The access token lasts 4 hours. After that
isLoggedIn()isfalse, the SDK removes it, and member calls throwmember_token_requiredwithout making a request. Show your Log in button again. - By default the login asks for no refresh token, so a member logs in again after 4 hours.
offlineAccess: truealso asks for a refresh token, and the SDK then renews the access token quietly. It is a long-lived credential in the browser, and it keeps working after logout (below). Turn it on only if members really need to stay signed in for days, and keepstorage: "session".
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
storage | Kept | Survives |
|---|---|---|
"session" (default) | sessionStorage | a reload; gone when the tab closes |
"local" | localStorage | closing the browser |
"memory" | the page only | nothing: 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
code | Status | Meaning | What to do |
|---|---|---|---|
member_token_required | 401 (SDK: 0) | No token was sent, or the SDK holds none (never logged in, or the session ended). | Offer login. |
member_token_invalid | 401 | The 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_member | 403 | A valid login, but that person is not a member of this club. | Tell the person. Logging in again will not help. |
login_failed, state_mismatch | 0 (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.