Integrate Hanko with a JavaScript backend
After successful authentication, Hanko generates a session token that is stored as a cookie. Use the session token to authenticate requests to your backend. This guide demonstrates how to implement session token validation in JavaScript to ensure that only properly authenticated users can access your application’s protected resources.
Get the Hanko API URL
Retrieve the API URL from the Hanko console.
Steps to Authenticate Requests
-
Retrieve the session token.
-
Verify the Session token using the Hanko Validate API endpoint.
Example function
The following section demonstrates how to validate session tokens against the Hanko backend. The specific implementation for retrieving the session token cookie will vary depending on your JavaScript runtime environment and framework.
Try it yourself
Hono.js example (React frontend)
Full source code available at GitHub.
Node and Express.js example (React frontend)
Full source code available at GitHub.
Node and Express.js example (Vue frontend)
Full source code available at GitHub.
Node and Express.js example (Svelte frontend)
Full source code available at GitHub.