@tmlmobilidade/interfaces
Version:
This package provides SDK-style connectors for interacting with databases (e.g., stops, plans, rides, alerts) and external providers (e.g., authentication, storage). It simplifies data access and integration across projects.
60 lines (59 loc) • 2.51 kB
TypeScript
import { type CreateUserDto, type LoginDto, type Organization, type Permission, type Session, type User } from '@tmlmobilidade/types';
export declare const AUTH_SESSION_COOKIE_NAME = "session_token";
declare class AuthProvider {
private static _instance;
/**
* Return the instance of the AuthProvider.
*/
static getInstance(): Promise<AuthProvider>;
/**
* Get the organization for a user based on their session token.
* @param sessionToken The session token to look up.
* @returns The user associated with the session token.
* @throws An HTTP UNAUTHORIZED error code if user or session not found
*/
getOrganizationFromSessionToken(sessionToken: string): Promise<Organization>;
/**
* Get Permissions for a user based on their session token.
* @param sessionToken The session token.
* @returns The permissions that the user has.
*/
getPermissionsFromSessionToken(sessionToken: string): Promise<Permission[]>;
/**
* Get Permissions for a user based on their user ID.
* @param userId The user ID (optional if sessionToken is provided).
* @returns The permissions that the user has.
*/
getPermissionsFromUserId(userId: string): Promise<Permission[]>;
/**
* Get a user object from their session token.
* @param sessionToken The session token to look up.
* @returns The user associated with the session token.
* @throws An HTTP UNAUTHORIZED error code if user or session not found
*/
getUserFromSessionToken(sessionToken: string): Promise<User>;
/**
* Login a user.
* @param username The username of the user
* @param password_hash The password hash of the user, already hashed with bcrypt in client
* @returns The newly created session for the logged in user
* @throws An HTTP error code:
* - UNAUTHORIZED if user not found or password is incorrect
* - INTERNAL_SERVER_ERROR if login fails
*/
login(loginDto: LoginDto): Promise<Session>;
/**
* Logout a user by removing their session.
* @param sessionToken The session token to logout.
*/
logout(sessionToken: string): Promise<void>;
/**
* Register a new user.
* @param createUserDto The data to create the user
* @throws An HTTP error code:
* - INTERNAL_SERVER_ERROR if user creation fails
*/
register(createUserDto: CreateUserDto): Promise<string>;
}
export declare const authProvider: AuthProvider;
export {};