Module 4 — Integrate Your App
Learning objectives
- Initialize
@faable/auth-jsand start a login.- Handle the callback and read the session + user.
- Know which SDK to reach for in browser vs server vs React.
The client SDK: @faable/auth-js
For browsers and React Native. It runs the Authorization Code + PKCE flow, manages the session, and refreshes tokens. You only need your tenant domain and Client ID.
import { createClient } from "@faable/auth-js";
export const auth = createClient({
domain: "your-tenant.auth.faable.link",
clientId: "<your_client_id>",
});Start a login
await auth.signInWithOauthConnection({
redirectTo: "https://app.example.com/callback", // must be in Allowed Callback URLs
});This redirects the browser to Faable’s /authorize with PKCE, state, and nonce
already set up. The user authenticates via whatever connections you enabled.
Handle the callback
On your callback route, let the SDK finish the exchange:
// at https://app.example.com/callback
const { session } = await auth.handleRedirectCallback();
// session has the tokens; the user is now signed inRead session & user
const session = await auth.getSession(); // null if not signed in
const accessToken = session?.access_token; // forward this to YOUR APIs
const user = session?.user; // identity from the ID tokenApply Module 1 here:
session.usercomes from the ID token (who the user is).session.access_tokenis what you put inAuthorization: Bearer …when calling your own backend. Don’t mix them up.
Log out
await auth.signOut(); // clears the local session; see OIDC Logout for RP-initiatedFor logging out across every app the user signed into, see OIDC Logout.
The Faable SDK family — pick the right one
| Package | Where it runs | Use it for |
|---|---|---|
@faable/auth-js | Browser / React Native | Login flow, session, token refresh (this module). |
@faable/auth-helpers-react | React | Hooks for session/user state (SessionContext). |
@faable/auth-sdk | Node.js server | Verify tokens; admin / Management API ops (Module 5). |
A quick win: the Next.js Quickstart wires all of this in an App Router project.
Common integration mistakes
- ❌ Sending the ID token to your API. Send the access token.
- ❌ Forgetting to add the prod callback URL → works locally, breaks in prod.
- ❌ Hardcoding tokens or putting a client secret in a browser app (public clients have no secret — PKCE replaces it).
- ❌ Calling APIs with an access token whose
audis not your API → the resource server rejects it (Module 5).
Check yourself
- After
handleRedirectCallback(), where do you get the value to call your own/api/ordersbackend? - Your login redirects fine locally but errors after deploying. Most likely cause?
- Which package would a Node.js cron job use to update users — and why not
@faable/auth-js?
Answers
- From
session.access_token(the access token), forwarded asAuthorization: Bearer …. - The production callback URL isn’t allow-listed on the client.
@faable/auth-sdk(server-side).@faable/auth-jsis a browser/mobile client SDK built around a user login + PKCE; a cron job has no user and needs the server-side client_credentials path (Module 5).
Last updated on