Skip to content

Commit

Permalink
Add default actions to auth sagas
Browse files Browse the repository at this point in the history
  • Loading branch information
shaunsaker committed May 2, 2018
1 parent 6c4e5c0 commit 5bf5e9c
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 31 deletions.
8 changes: 8 additions & 0 deletions sagas/auth/getAuth.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,18 @@ export default function* getAuth(action) {
...action.meta.nextAction,
payload: response,
});
} else {
yield put({
type: 'SIGN_IN_USER',
payload: response,
});
}
} else {
yield put({
type: 'signInAnonymously',
meta: {
nextAction: action.meta && action.meta.nextAction,
},
});
}
} catch (error) {
Expand Down
37 changes: 20 additions & 17 deletions sagas/auth/getCredentialAndSignIn.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,31 @@ export default function* getCredentialAndSignIn(action) {
auth[service],
action.payload.email,
action.payload.password,
); // NOTE: only getCredentialFromEmail is expecting these: args[1], args[2]
); // NOTE: only getCredentialFromEmail is expecting email and password

if (getCredentialResponse) {
try {
yield call(
auth.signInWithCredential,
getCredentialResponse, // the credential
);
try {
const signInWithCredentialResponse = yield call(
auth.signInWithCredential,
getCredentialResponse, // the credential
);

if (action.nextAction) {
yield put({
...action.nextAction,
payload: getCredentialResponse,
});
}
} catch (error) {
if (action.nextAction) {
yield put({
type: 'SET_SYSTEM_MESSAGE',
payload: utils.createError(error),
error: true,
...action.nextAction,
payload: getCredentialResponse,
});
} else {
yield put({
type: 'SIGN_IN_USER',
payload: signInWithCredentialResponse,
});
}
} catch (error) {
yield put({
type: 'SET_SYSTEM_MESSAGE',
payload: utils.createError(error),
error: true,
});
}
} catch (error) {
yield put({
Expand Down
5 changes: 5 additions & 0 deletions sagas/auth/getCredentialFromEmail.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ export default function* getCredentialFromEmail(action) {
...action.meta.nextAction,
payload: response,
});
} else {
yield put({
type: 'SIGN_IN_USER',
payload: response,
});
}
} catch (error) {
yield put({
Expand Down
5 changes: 5 additions & 0 deletions sagas/auth/getCredentialFromFacebook.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ export default function* getCredentialFromFacebook(action) {
...action.meta.nextAction,
payload: response,
});
} else {
yield put({
type: 'SIGN_IN_USER',
payload: response,
});
}
} catch (error) {
yield put({
Expand Down
5 changes: 5 additions & 0 deletions sagas/auth/getCredentialFromGoogle.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ export default function* getCredentialFromGoogle(action) {
...action.meta.nextAction,
payload: response,
});
} else {
yield put({
type: 'SIGN_IN_USER',
payload: response,
});
}
} catch (error) {
yield put({
Expand Down
8 changes: 8 additions & 0 deletions sagas/auth/sendPasswordResetEmail.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ export default function* sendPasswordResetEmail(action) {
...action.meta.nextAction,
payload: response,
});
} else {
yield put({
type: 'SET_SYSTEM_MESSAGE',
payload: {
message: 'Email sent successfully',
},
error: true,
});
}
} catch (error) {
yield put({
Expand Down
8 changes: 7 additions & 1 deletion sagas/auth/signInAnonymously.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,17 @@ import utils from '../../utils';
export default function* signInAnonymously(action) {
try {
const response = yield call(auth.signInAnonymously);
const { user } = response; // omits additionalUserInfo

if (action.meta && action.meta.nextAction) {
yield put({
...action.meta.nextAction,
payload: response,
payload: user,
});
} else {
yield put({
type: 'SIGN_IN_USER',
payload: user,
});
}
} catch (error) {
Expand Down
21 changes: 8 additions & 13 deletions sagas/auth/signInWithCredential.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,17 @@ export default function* signInWithCredential(action) {
...action.meta.nextAction,
payload: response,
});
}
} catch (error) {
if (error.message.code === 'auth/account-exists-with-different-credential') {
yield put({
type: 'SET_SYSTEM_MESSAGE',
payload: utils.createError(
"Hello! You've already signed in with someone else. Please try another option.",
),
error: true,
});
} else {
yield put({
type: 'SET_SYSTEM_MESSAGE',
payload: utils.createError(error),
error: true,
type: 'SIGN_IN_USER',
payload: response,
});
}
} catch (error) {
yield put({
type: 'SET_SYSTEM_MESSAGE',
payload: utils.createError(error),
error: true,
});
}
}
4 changes: 4 additions & 0 deletions sagas/auth/signOut.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ export default function* signOut(action) {
...action.meta.nextAction,
payload: response,
});
} else {
yield put({
type: 'SIGN_OUT_USER',
});
}
} catch (error) {
yield put({
Expand Down

0 comments on commit 5bf5e9c

Please sign in to comment.