Authentication > Session Context
Authentication > Session ContextKroxt BaaS SDK v1.0.5

Session Context

Get Logged-In User Profile context:
auth.ts
1
2
3
4
const user = await baas.auth.me();
if (user) {
  console.log("Welcome back:", user.displayName, user.email);
}
Update User Profile:

Update the profile fields (displayName, avatar, metadata) of the logged-in user. Note: The user email cannot be updated directly via this method due to multi-tenant database namespace isolation.

auth.ts
1
2
3
4
5
6
const updatedUser = await baas.auth.update({
  displayName: "Alex New Name",
  avatar: "https://example.com/avatar.png",
  metadata: { age: 29 },
});
console.log("Updated profile:", updatedUser.displayName);
Update User Password:

Update the user's password. Doing so invalidates the current session on the backend and clears all local tokens globally (requiring a new login):

auth.ts
1
2
// This will clear local storage credentials and force a re-login
await baas.auth.updatePassword("NewSecurePassword123!");
Sign Out (Clears stored tokens):
auth.ts
1
await baas.auth.logout();

TypeScript Type Integration

When retrieving the active profile context, the SDK resolves to a KroxtUser directly (or returns null if unauthenticated):

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

const user: KroxtUser | null = await baas.auth.me();

if (user) {
  console.log("Active User Status:", user.status); // "active" | "disabled"
  console.log("Active User Name:", user.displayName);
}