aretherecookies-mobile/js/apis/Auth0.js

53 lines
1.1 KiB
JavaScript
Raw Normal View History

2018-08-25 12:13:09 -05:00
// @flow
import Auth0 from 'react-native-auth0';
2020-03-29 19:47:33 +00:00
import { type EmailAndPassword } from '../AuthManager';
2018-08-25 12:13:09 -05:00
let auth0Instance = null;
export type Auth0User = {
2020-03-29 19:47:33 +00:00
email: string,
2018-08-25 12:13:09 -05:00
accessToken: string,
expiresIn: number,
2020-03-29 19:47:33 +00:00
idToken: string,
2018-08-25 12:13:09 -05:00
};
const getAuth0Instance = () => {
return (
auth0Instance ||
new Auth0({
2020-04-03 21:21:00 -05:00
domain: 'wheresthetp.auth0.com',
2018-08-25 12:13:09 -05:00
clientId: 'hyrRaEFeh4Eo1NYTQwDB1phqdSqfROxg',
})
);
};
2020-03-29 19:47:33 +00:00
export const loginAuth0 = async ({ email, password }: EmailAndPassword): Promise<?Auth0User> => {
const creds = await getAuth0Instance().auth.passwordRealm({
2020-03-29 19:47:33 +00:00
username: email,
password,
realm: 'Username-Password-Authentication',
});
2020-03-29 19:47:33 +00:00
return {
email,
...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',
2020-04-03 21:21:00 -05:00
audience: 'https://wheresthetp.auth0.com/userinfo',
});
return creds;
2018-08-25 12:13:09 -05:00
};