mirror of
https://gitlab.com/wheres-the-tp/ui-mobile.git
synced 2026-01-25 04:24:56 -06:00
52 lines
1.1 KiB
JavaScript
52 lines
1.1 KiB
JavaScript
// @flow
|
|
import Auth0 from 'react-native-auth0';
|
|
import { type EmailAndPassword } from '../AuthManager';
|
|
|
|
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: 'hyrRaEFeh4Eo1NYTQwDB1phqdSqfROxg',
|
|
})
|
|
);
|
|
};
|
|
|
|
export const loginAuth0 = async ({ email, password }: EmailAndPassword): Promise<?Auth0User> => {
|
|
const creds = await getAuth0Instance().auth.passwordRealm({
|
|
username: email,
|
|
password,
|
|
realm: 'Username-Password-Authentication',
|
|
});
|
|
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',
|
|
audience: 'https://wheresthetp.auth0.com/userinfo',
|
|
});
|
|
return creds;
|
|
};
|