UNPKG

react-native-lightspeedsdk

Version:
113 lines (92 loc) 3.92 kB
'use strict'; import {NativeEventEmitter} from 'react-native'; import UserProfile from './models/UserProfile'; import BasicUserInfo from './models/BasicUserInfo'; const NativeRegistrationCoordinator = require('react-native').NativeModules.LSRegistrationCoordinator; const RegistrationEventEmitter = new NativeEventEmitter(NativeRegistrationCoordinator); export type SocialLoginProviderType = 'facebook'; module.exports = { addLogoutListener(listener: Function){ return RegistrationEventEmitter.addListener(NativeRegistrationCoordinator.UserLogoutNotification, listener); }, removeLogoutListener(listener: Function) { RegistrationEventEmitter.removeListener(NativeRegistrationCoordinator.UserLogoutNotification, listener); }, /** * Retrieves the supported and later supported countries and languages */ getCountryLanguages() : Promise<?CountryLanguages> { return NativeRegistrationCoordinator.getCountryLanguages(); }, /** * Checks if the provided email is already registered */ isEmailRegistered(email: string): Promise<?BasicUserInfo> { return NativeRegistrationCoordinator.isEmailRegistered(email); }, /** * Getter for the current User Profile of the logged in User. */ getLoggedInUser(): Promise<?UserProfile> { return new Promise((resolve, reject) => { NativeRegistrationCoordinator.loggedInUser((tokenMap, error) => { if (tokenMap) { let profile = new UserProfile(tokenMap); resolve(profile); } else { resolve(null); } }); }); }, // reason object e.g.: {code: 6001, reason: "Rejected Country/Language"} sessionClearedReason(): Promise<Object> { return new Promise((resolve, reject) => { NativeRegistrationCoordinator.sessionClearedReason((reason) => { resolve(reason); }); }); }, /** * Registers the user using Mobile services */ register(email: string, password:string, firstName:string, lastName:string, zipCode:string, gender:int, birthDate: string, languageCode: string, countryCode: string): Promise<?UserProfile> { return NativeRegistrationCoordinator.register(email, password, firstName, lastName, zipCode, gender, birthDate, languageCode, countryCode); }, /** * Log the user in using Mobiles services */ login(email: string, password:string): Promise<?UserProfile> { return NativeRegistrationCoordinator.login(email, password); }, /** * Log the user in using the social provider credentials via Mobile Services */ socialLogin(gigyaId: string, provider: SocialLoginProviderType, providerUId: string, accessToken: string, email: string, firstName: string, lastName: string, isSiteUID: bool, languageCode: string, countryCode: string): Promise<?UserProfile> { return NativeRegistrationCoordinator.loginWithSocialProvider(gigyaId, provider, providerUId, accessToken, email, firstName, lastName, isSiteUID, languageCode, countryCode); }, /** * Reset the password of the provided email address */ resetPassword(email: string): Promise<?Object>{ return NativeRegistrationCoordinator.resetPassword(email); }, /** * Log the user out using Mobile Services */ logout() { NativeRegistrationCoordinator.logout(); }, /** * Link the user Social Provider account via Mobile Services */ socialLink(gigyaId: string, provider: SocialLoginProviderType, providerUId: string, accessToken: string) : Promise<?SingleAchievement>{ return NativeRegistrationCoordinator.socialLink(gigyaId, provider, providerUId, accessToken); }, /** * Unlink the user Social Provider account via Mobile Services */ socialUnlink(provider: SocialLoginProviderType) : Promise<?Object>{ return NativeRegistrationCoordinator.socialUnlink(provider); } };