Authentication > Register & Login
Authentication > Register & LoginKroxt BaaS SDK v1.0.5

Register & Login

Register a User:
auth.ts
1
2
3
4
5
6
7
const session = await baas.auth.register({
  email: "user@example.com",
  password: "SecurePassword123!",
  displayName: "Alex Doe",
  avatar: "https://example.com/avatar.png",
  metadata: { role: "admin", age: 28 },
});
Sign In:
auth.ts
1
2
3
4
5
const session = await baas.auth.login({
  email: "user@example.com",
  password: "SecurePassword123!",
});
console.log("Logged In Token:", session.accessToken);

TypeScript Type Integration

The SDK automatically unwraps response success envelopes at runtime, returning the target type directly. You can import type helpers directly from the SDK:

types.ts
1
2
3
4
5
6
7
8
9
import type { AuthSession } from "@kroxt/baas-sdk";

const session: AuthSession = await baas.auth.login({
  email: "user@example.com",
  password: "SecurePassword123!",
});

console.log("Welcome back:", session.user.displayName);
console.log("Access Token:", session.accessToken);