@ngx-addons/omni-auth-core
Version:
Core library for authentication in Angular applications.
255 lines (241 loc) • 9.46 kB
TypeScript
import * as i0 from '@angular/core';
import { PipeTransform, Signal, ResourceRef, Type, InjectionToken, Provider } from '@angular/core';
import { HttpInterceptorFn } from '@angular/common/http';
import { CanActivateFn } from '@angular/router';
declare class OmniAuthError {
error: Error | unknown;
constructor(error: Error | unknown);
getErrorMessage(): string;
}
type ActionErrorCode = 'unknown' | 'signInWithRedirectFailure' | 'userDoesNotExist' | 'alreadySignedIn' | 'incorrectUsernameOrPassword' | 'usernameNotFound' | 'invalidConfiguration' | 'cancelledFlow' | 'invalidCode';
declare class FlowError extends OmniAuthError {
source: 'signIn' | 'signInWithProvider' | 'forgotPassword' | 'signUp' | 'confirmSignUp' | 'resendSignUpCode' | 'confirmForgotPassword' | 'signOut';
code: ActionErrorCode;
error: Error | unknown;
silent: boolean;
constructor(source: 'signIn' | 'signInWithProvider' | 'forgotPassword' | 'signUp' | 'confirmSignUp' | 'resendSignUpCode' | 'confirmForgotPassword' | 'signOut', code: ActionErrorCode, error: Error | unknown, silent?: boolean);
}
declare const defaultContent: {
loggedIn: {
welcomeMessage: string;
welcomeMessageNoDisplayName: string;
};
common: {
emailLabel: string;
passwordLabel: string;
nameLabel: string;
nameErrorRequiredText: string;
nameErrorMinLengthText: string;
namePlaceholder: string;
emailErrorRequiredText: string;
emailErrorPatternText: string;
emailPlaceholder: string;
passwordErrorRequiredText: string;
passwordErrorMinLengthText: string;
passwordPatternText: string;
passwordPlaceholder: string;
codeLabel: string;
codeErrorRequiredText: string;
codePlaceholder: string;
backToSignInLabel: string;
icons: {
back: string;
email: string;
};
};
signIn: {
title: string;
errorSubmitMessage: string;
submitLabel: string;
forgetPassword: string;
};
signUp: {
title: string;
errorSubmitMessage: string;
submitLabel: string;
termsAndConditionsText: string;
termsAndConditionsLinkText: string;
};
confirmationSignUp: {
subTitle: string;
paragraph: string;
errorSubmitMessage: string;
submitLabel: string;
resendLabel: string;
errorResendMessage: string;
};
resetPassword: {
title: string;
sendCodeMessage: string;
providePasswordMessage: string;
repeatPassword: string;
errorSubmitMessage: string;
errorSendCodeMessage: string;
sendCodeLabel: string;
submitLabel: string;
};
socialButtons: {
orLine: string;
signInWithGoogle: string;
signInWithApple: string;
signInWithFacebook: string;
};
errors: {
invalidCode: string;
usernameNotFound: string;
incorrectUsernameOrPassword: string;
userDoesNotExist: string;
alreadySignedIn: string;
signInWithRedirectFailure: string;
invalidConfiguration: string;
cancelledFlow: string;
unknown: string;
};
};
type ContentConfig = typeof defaultContent;
declare class ErrorMessagePipe implements PipeTransform {
#private;
transform(source: FlowError['source'], messages: ContentConfig['errors']): Signal<string | null>;
static ɵfac: i0.ɵɵFactoryDeclaration<ErrorMessagePipe, never>;
static ɵpipe: i0.ɵɵPipeDeclaration<ErrorMessagePipe, "errorMessage", true>;
}
declare class RuntimeError extends OmniAuthError {
error: Error | unknown;
possibleSolution?: string | undefined;
constructor(error: Error | unknown, possibleSolution?: string | undefined);
}
declare class ActionErrorCollectorService {
#private;
readonly currentError: Signal<FlowError | null>;
reset(): void;
handle(error: FlowError): void;
static ɵfac: i0.ɵɵFactoryDeclaration<ActionErrorCollectorService, never>;
static ɵprov: i0.ɵɵInjectableDeclaration<ActionErrorCollectorService>;
}
/**
* Defines common patterns used for validation in the OmniAuth Core library.
*
* These patterns are used for validating passwords and email addresses.
*/
declare const passwordPattern: RegExp;
declare const emailPattern: RegExp;
declare const patterns_d_emailPattern: typeof emailPattern;
declare const patterns_d_passwordPattern: typeof passwordPattern;
declare namespace patterns_d {
export {
patterns_d_emailPattern as emailPattern,
patterns_d_passwordPattern as passwordPattern,
};
}
declare const isError: (response: OmniAuthError | void) => response is OmniAuthError;
type CustomSignInProviderKey = string;
type SocialSignInProviderKey = 'google' | 'facebook' | 'apple' | 'github' | 'microsoft';
type SignInProviderKey = CustomSignInProviderKey | SocialSignInProviderKey;
type AuthState = {
state: 'unknown' | 'authenticated' | 'unauthenticated' | 'error';
user?: {
displayName?: string;
email?: string;
name?: string;
phone?: string;
verified: boolean;
};
error?: OmniAuthError;
};
declare abstract class OmniAuthService {
abstract authState: ResourceRef<AuthState>;
abstract currentUser: Signal<AuthState['user']>;
abstract getToken: () => Promise<string | null>;
abstract signOut(fromAllDevices?: boolean): Promise<void | FlowError>;
abstract resendSignUpCode(params: {
email: string;
}): Promise<void | FlowError>;
abstract signUp(params: {
email: string;
password: string;
name: string;
attributes?: Record<string, string | boolean>;
}): Promise<void | FlowError>;
abstract confirmSignUp(params: {
email: string;
code: string;
}): Promise<void | FlowError>;
abstract signIn(params: {
email: string;
password: string;
}): Promise<void | FlowError>;
abstract forgotPassword(params: {
email: string;
}): Promise<void | FlowError>;
abstract confirmForgotPassword(params: {
email: string;
code: string;
newPassword: string;
}): Promise<void | FlowError>;
abstract signInWithProvider(providerKey: SocialSignInProviderKey | CustomSignInProviderKey): Promise<void | FlowError>;
}
type AuthConfig = {
/** @description Authentication service class */
authService: Type<OmniAuthService>;
bearerAuthentication?: {
/**
* @description List of endpoints that do not require authentication, can be RegExp or string.
* In case of empty array, all endpoints will require authentication.
* */
whitelistedEndpoints: (RegExp | string)[];
/** @description Authentication token header name, default is 'Authorization' */
headerName?: string;
/** @description Authentication token suffix, default is "Bearer " */
headerValuePrefix?: string;
};
routing?: {
/** @description The route to redirect to after successful login */
secured: string[];
/** @description The route to redirect to after logout */
guest: string[];
};
validation?: {
/** @description Email validation pattern, used in sign out / sign in method */
emailPattern?: RegExp;
/** @description Password validation pattern, used in sign out / sign in method */
passwordPattern?: RegExp;
};
};
declare const AUTH_CONFIG: InjectionToken<AuthConfig>;
declare const configureAuth: (params: AuthConfig) => Provider[];
declare const jwtInterceptor: HttpInterceptorFn;
/**
* @description Guard that checks if the user is authenticated user otherwise redirects to the specified route.
* @param config
*/
declare const onlyAuthenticated: (config?: {
/**
* @description The route to redirect if someone is not authenticated. If not provided, will use the default from the AuthConfig.
*/
redirectTo?: string[];
}) => CanActivateFn;
/**
* @description Guard that checks if the user is not authenticated otherwise redirects to the specified route.
* @param config
*/
declare const onlyGuest: (config?: {
/**
* @description The route to in case of unauthenticated user. If not provided, will use the default from the AuthConfig.
*/
redirectTo?: string[];
}) => CanActivateFn;
type AuthStep = 'login' | 'register' | 'reset_password' | 'confirm_reset_password' | 'confirm_sign_up';
declare class AuthRouteService {
#private;
readonly currentStep: i0.WritableSignal<AuthStep>;
readonly currentEmail: i0.WritableSignal<string | null>;
nextStep(state: AuthStep, details?: {
email?: string;
}): void;
navigateToGuestPage(rememberPage?: boolean): Promise<boolean> | undefined;
navigateToSecuredPage(): Promise<boolean> | undefined;
static ɵfac: i0.ɵɵFactoryDeclaration<AuthRouteService, never>;
static ɵprov: i0.ɵɵInjectableDeclaration<AuthRouteService>;
}
export { AUTH_CONFIG, ActionErrorCollectorService, AuthRouteService, ErrorMessagePipe, FlowError, OmniAuthError, OmniAuthService, RuntimeError, configureAuth, defaultContent, isError, jwtInterceptor, onlyAuthenticated, onlyGuest, patterns_d as patterns };
export type { AuthConfig, AuthState, ContentConfig, CustomSignInProviderKey, SignInProviderKey, SocialSignInProviderKey };