aretherecookies-mobile/js/apis/Auth0.js

46 lines
1 KiB
JavaScript

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