// @flow import Auth0 from 'react-native-auth0'; import { type EmailAndPassword } from '../AuthManager'; import { auth0ClientId } from '../constants/AppConstants'; let auth0Instance = null; export type Auth0User = { email: string, accessToken: string, expiresIn: number, idToken: string, }; const getAuth0Instance = () => { return ( auth0Instance || new Auth0({ domain: 'wheresthetp.auth0.com', clientId: auth0ClientId, }) ); }; export const loginAuth0 = async ({ email, password }: EmailAndPassword): Promise => { const creds = await getAuth0Instance().auth.passwordRealm({ username: email, password, realm: 'Username-Password-Authentication', }); return { email, ...creds, }; }; export const createAuth0User = async ({ email, password }) => { const creds = await getAuth0Instance().auth.createUser({ email, username: email, password, connection: 'Username-Password-Authentication', }); return creds; }; export const resetAuth0Password = async () => { const creds = await getAuth0Instance().webAuth.authorize({ scope: 'openid profile email', audience: 'https://wheresthetp.auth0.com/userinfo', }); return creds; };