Add a login route
A server-rendered application needs a sign-in endpoint.
Kinde · Module
Kinde's TypeScript SDK login method creates a redirect URL for sign-in. Call it from a login route and redirect the browser to the returned URL.
The TypeScript SDK's login method creates the authorization redirect URL for a user sign-in. A server route calls it with the session manager, then redirects the browser to Kinde so authentication can occur.
kindeClient.login(sessionManager)| Name | Type | Description |
|---|---|---|
sessionManager | SessionManager | Session state manager used by the authentication client. |
A redirect URL that sends the user to Kinde for sign-in.
login starts sign-in by producing a URL that points the browser at Kinde./login and connect it to the SDK method.import express from "express";
import { KindeClient } from "@kinde/js-node";
const app = express();
const kindeClient = new KindeClient({
clientId: process.env.KINDE_CLIENT_ID!,
clientSecret: process.env.KINDE_CLIENT_SECRET!,
authDomain: process.env.KINDE_AUTH_DOMAIN!,
redirectUri: "http://localhost:3000/callback",
});
app.get("/login", async (_req, res) => {
const loginUrl = await kindeClient.login(sessionManager);
res.redirect(loginUrl.toString());
});The route obtains Kinde's sign-in redirect URL and sends the browser to it.
A server-rendered application needs a sign-in endpoint.
An application delegates credential entry and authentication to Kinde.
A session-aware backend begins an OAuth sign-in flow.
login method do?The method constructs a redirect URL that sends the user to Kinde to sign in. In a server application, the route should call it with the session manager and return a redirect response.
Follow-up: Why pass a session manager? It supplies the session context required by the SDK while constructing the authentication flow.
A typical implementation maps /login to an asynchronous handler, calls kindeClient.login(sessionManager), converts the resulting URL to a string, and redirects the response there.
Follow-up: What should happen after authentication? Kinde should return the browser to a configured callback URL so the application can complete the session flow.
Login is part of the redirect-based authentication flow rather than a local password-checking function. The user is sent to Kinde, where sign-in takes place.
Follow-up: How could registration be exposed similarly? Add a /register route and connect it to the SDK's registration method.
registerSessionManagerKindeClient