import {
FaceLoginResponse,
LoginProviderType,
LoginWithIdTokenRequest,
} from '@haechi-labs/face-types';
import { Internal } from './Internal';
/**
* The interface about authentication.
*
* @category API
*/
export class Auth {
private readonly internal: Internal;
constructor(internal: Internal) {
this.internal = internal;
}
/**
* Sign-up(if new user) or login function. Need to initialize face with environment, blockchain and api key first.
*
* You can choose three options, Google, Facebook, and Apple login.
*
* @method
* @returns {Promise<FaceLoginResponse>} FaceLoginResponse. Unique user ID using on Face server and wallet address.
*/
async login(): Promise<FaceLoginResponse | null> {
return await this.internal.loginWithCredential();
}
/**
* Directly sign-up(if new user) or login using social login. Need to initialize face with environment, blockchain and api key first.
*
* Pass the desired login provider to parameter.
*
* @method
* @param {LoginProviderType} provider - 'google.com' | 'facebook.com' | 'apple.com'
* @returns {Promise<FaceLoginResponse>} FaceLoginResponse. Unique user ID using on Face server and wallet address.
*/
async directSocialLogin(provider: LoginProviderType): Promise<FaceLoginResponse | null> {
return this.internal.directSocialLogin(provider);
}
/**
* Login using the idToken published from social providers and Signature. Need to initialize face with environment, blockchain and api key first.
* You can make a Signature using Face Wallet SDK API Secret.
*
* Pass the the idToken and Signature to parameters.
*
* @method
* @param {LoginWithIdTokenRequest} loginWithIdTokenRequest
* @returns {Promise<FaceLoginResponse>} FaceLoginResponse. Unique user ID using on Face server and wallet address.
*/
async loginWithIdToken(
loginWithIdTokenRequest: LoginWithIdTokenRequest
): Promise<FaceLoginResponse | null> {
return this.internal.loginWithIdToken(loginWithIdTokenRequest);
}
/**
* Log out Face Wallet.
*
* It will be resolved after successful logout.
*
* @method
* @returns {Promise<void>}
*/
async logout(): Promise<void> {
await this.internal.logout();
}
/**
* Return user information.
*
* @method
* @returns {Promise<FaceLoginResponse>}
*/
async getCurrentUser(): Promise<FaceLoginResponse | null> {
return await this.internal.getCurrentUser();
}
/**
* Check if user is already logged in.
*
* @returns {Promise<boolean>}
*/
async isLoggedIn(): Promise<boolean> {
return await this.internal.isLoggedIn();
}
}
Source