Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(demos): getUser on changed route
- Loading branch information
1 parent
9b88427
commit ada2dbb
Showing
7 changed files
with
37 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
packages/demo/src/modules/common/signals/getCurrentUser.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import {input, set, state, when} from 'cerebral/operators' | ||
import getUser from '../../user/actions/getUser' | ||
|
||
const getCurrentUser = [ | ||
when(state`user.$loggedIn`), { | ||
true: [], | ||
false: [ | ||
getUser, { | ||
success: [ | ||
set(state`user.$loggedIn`, true), | ||
set(state`user.currentUser`, input`user`) | ||
], | ||
error: [ | ||
set(state`user.$loggedIn`, false) | ||
] | ||
} | ||
] | ||
} | ||
] | ||
|
||
export default getCurrentUser |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
function getUser ({firebase, path}) { | ||
return firebase.getUser() | ||
.then(path.success) | ||
.catch(path.error) | ||
} | ||
|
||
export default getUser |