Backend
Integrate Hanko with Node backend
Obtain your Hanko API URL
- Log in to Hanko Cloud and select your project.
- Navigate to the
Dashboard
. - Find your
API URL
on the top of the dashboard. - Copy the URL to a
.env
file..env
Validate a session token
Upon a successful login, Hanko sends a cookie containing a JSON Web Token (JWT). You can use this JWT to authenticate requests on your backend.
See here for more details on sessions
The steps required to validate a session JWT depend on whether sessions are configured to be stateful (server-side) or stateless.
- Validate the session using the
sessions/validate
endpoint: Use the session token to retrieve info about session validity, expiry, and user ID of the user the session is associated with.
Examples
Express
In the following example, we demonstrate how to implement a custom middleware in an Express.js application.
Try it yourself
Node and Express.js example (React frontend)
Full source code available on our GitHub.
Node and Express.js example (Vue frontend)
Full source code available on our GitHub.
Node and Express.js example (Svelte frontend)
Full source code available on our GitHub.