// Dependencies import ConnectyCube from 'react-native-connectycube'; // Dto import { Session, UserCredentials } from './dto/authentication'; import { AppCredentials, AppConfig } from './dto/app'; // Helpers import * as authHelper from './authHelper'; /** * Service to manage authentication in the chat app. * @class Auth * @author Daniel Mejia */ export class Auth { async validateSession(): Promise { const localCredentials = await authHelper.getLocalCredentials(); if (localCredentials) { const { login, password } = localCredentials; return this.signIn({ login, password }); } return undefined; } signIn = async (userCredentials: UserCredentials): Promise => { const session = await ConnectyCube.createSession(userCredentials); authHelper.persistCredentials(userCredentials); return session; } signOut = async (): Promise => { await authHelper.removeCredentials(); await ConnectyCube.logout(); } } export default Auth;