Skip to content

Commit

Permalink
fix: ability to create roles
Browse files Browse the repository at this point in the history
  • Loading branch information
hopetambala committed Nov 4, 2020
1 parent 2e552ca commit ed40e28
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 20 deletions.
28 changes: 8 additions & 20 deletions domains/Auth/SignUp/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
import { ScrollView } from 'react-native-gesture-handler';
import { Formik } from 'formik';
import * as yup from 'yup';
import { retrieveSignUpFunction, retrieveSignInFunction, retrieveCurrentUserFunction } from '../../../services/parse/auth';
import { retrieveSignUpFunction } from '../../../services/parse/auth';

import FormInput from '../../../components/FormikFields/FormInput';
import TermsModal from '../../../components/TermsModal';
Expand Down Expand Up @@ -88,25 +88,13 @@ export default function SignUp({ navigation }) {
} else {
retrieveSignUpFunction(values)
.then((user) => {
const userString = JSON.stringify(user);
const userValues = JSON.parse(userString);
const { username } = userValues;
// sign user in after successful sign up
retrieveSignInFunction(username, values.password)
.then(() => {
// user signed in and signed up
// store organization for future use
const currentUser = retrieveCurrentUserFunction();
getData('organization').then((organization) => {
if (organization !== currentUser.organization) {
storeData(currentUser.organization, 'organization');
}
});
navigation.navigate('Root');
}, () => {
// sign in failed, alert user
});
}, (error) => {
getData('organization').then((organization) => {
if (organization !== user.get('organization')) {
storeData(user.get('organization'), 'organization');
}
navigation.navigate('Root');
});
}).catch((error) => {
// sign up failed alert user
console.log(`Error: ${error.code} ${error.message}`); // eslint-disable-line
alert(I18n.t('signUp.usernameError')); // eslint-disable-line
Expand Down
7 changes: 7 additions & 0 deletions services/parse/auth/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ function initialize() {
Parse.initialize(parseAppId, parseJavascriptKey);
Parse.serverURL = parseServerUrl;
console.log(`Initialize Parse with App ID:${parseAppId}, Javascript Key: ${parseJavascriptKey}`); // eslint-disable-line
createRoles();
}

function createRoles() {
Parse.Cloud.run('createAdminRole');
Parse.Cloud.run('createManagerRole');
Parse.Cloud.run('createContributorRole');
}

function retrieveSignUpFunction(params) {
Expand Down

0 comments on commit ed40e28

Please sign in to comment.