Receive webhooks
Optional, recommended for production. Login works without it, but if the user signs out from Block-Auth (Identity, the extension or another device), your app won’t know.
How you add the backend login routes
Applies from here on. You pick it once in the SDK Quickstart.
Receive webhooks
Block-Auth calls your backend when a user signs out of your app from Block-Auth (signout) or unlinks your app (account.unlinked), so you can close their session too.
This is how a sign-out made in Block-Auth (Identity, the extension or another device) reaches your page:
- 1Block-AuthThe user signs out
- 2Block-Auth → Your backendPOST /webhook · signout
- 3Your backendSaves the sign-out
- 4Your frontend → Your backendGET /me on focus or every 60 s
- 5Your backend → Your frontend401
- 6Your frontendShows the user signed out
Block-Auth widget
Your session
Hosted by Block-Auth
- 1The user signs out
- 2POST /webhook · signout
- 3Saves the sign-out
- 4GET /me on focus or every 60 s
- 5401
- 6Shows the user signed out
- In the Dashboard, open your application's Authentication settings. In the third URL field, shown as "When user fails to log in", type the path
/auth/blockauth/webhook(your domain is already filled in).
- Add these options to the
BlockAuthRoutesfrom step 2, so the package knows how to remember a sign-out and check it.POST /webhookis already there: it verifies the request and callsonSignoutoronUnlinked. ThenisRevokedcloses every session that started before that sign-out:
export const routes = new BlockAuthRoutes({
apiKey: process.env.BLOCKAUTH_API_KEY,
apiSecret: process.env.BLOCKAUTH_API_SECRET,
appUrl: process.env.APP_URL,
onSignout: (event) => saveSignout(event.address, event.iat),
onUnlinked: async (event) => {
await saveSignout(event.address, event.iat)
await removeLink(event.externalId)
},
isRevoked: async (user) => ((await lastSignout(user.address.toLowerCase())) ?? -1) >= user.loggedInAt,
})
saveSignout, lastSignout, removeLink are yours: replace them with your app’s own functions (your database, your cache…).
saveSignout, lastSignout and removeLink are yours: keep them in your database or a shared cache such as Redis, so every server instance sees them. address arrives in lowercase and iat and loggedInAt are Unix seconds.
isRevokedruns on everyGET /meand every time you read the user. The widget asks/mewhen the tab gets focus and every minute, so the page signs out by itself.- To reject a repeated delivery, add
isReplay(jti)and returntrueif you already saw thatjti.

