@punhlainghospitals/auth-backend
v0.0.9
Published
Auth backend utilities package for Pun Hlaing Hospitals
Readme
@punhlainghospitals/auth-backend
TypeScript helpers for talking to the Pun Hlaing Hospitals auth backend.
Install
npm install @punhlainghospitals/auth-backendThis library ships ES module, CommonJS, and TypeScript type definitions.
Configuration
By default all calls go to:
AUTH_SERVER_API:https://phhplatform.punhlainghospitals.com/api/auth
If you need a different auth API URL, configure it at build time (for example by replacing LibEnv.AUTH_SERVER_API in your bundler).
Exports
From src/index.ts the package re‑exports:
getCurrentUser(accessToken: string): Promise<UserInterface | null>validateAccessToken(accessToken: string): Promise<AxiosResponse<AccessTokenValidationInterface>>loginWithOtt(token: string): Promise<AxiosResponse<TokenIssueInterface>>refreshToken(refreshToken: string): Promise<AxiosResponse<TokenIssueInterface>>AuthProviderEnumUserInterfaceTokenIssueInterfaceAccessTokenValidationInterface
Basic usage
import {
getCurrentUser,
validateAccessToken,
loginWithOtt,
refreshToken,
AuthProviderEnum,
type UserInterface,
} from '@punhlainghospitals/auth-backend';
// Get the current user profile
const user: UserInterface | null = await getCurrentUser('<access-token>');
// Validate an access token
const validation = await validateAccessToken('<access-token>');
if (validation.data.success) {
console.log('Token is valid for user', validation.data.userId);
}
// Login with one‑time token
const loginResult = await loginWithOtt('<ott-token>');
console.log('Logged in as', loginResult.data.user.name);
// Refresh access token
const refreshed = await refreshToken('<refresh-token>');
console.log('New access token', refreshed.data.accessToken);Types and enums
You can use the exported interfaces and enum for strong typing:
UserInterfaceTokenIssueInterfaceAccessTokenValidationInterfaceAuthProviderEnum('google' | 'local')
