-
-
Save spac3unit/a598ada99b33d63d714e5bb2c7243e39 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| import {createStore, createEvent, createEffect} from 'effector'; | |
| import {authService, googleAuthProvider} from '../cloudStore'; | |
| const userStateChange = createEvent('userStateChange'); | |
| const signIn = createEffect('signIn').use(() => | |
| authService.signInWithPopup(googleAuthProvider) | |
| ); | |
| const signOut = createEffect('signOut').use(() => authService.signOut()); | |
| const $user = createStore(null); | |
| const $loginError = createStore(null); | |
| const $isUserUpdating = createStore(false); | |
| $user.on(userStateChange, (_, currentUser) => currentUser); | |
| authService.onAuthStateChanged(userStateChange); | |
| $isUserUpdating | |
| .reset(signIn.done) | |
| .reset(signIn.fail) | |
| .reset(signOut.done) | |
| .reset(signOut.fail) | |
| .on(signIn, () => true) | |
| .on(signOut, () => true); | |
| const $isAuth = $user.map(Boolean); | |
| export const userModel = { | |
| effects: { | |
| signIn, | |
| signOut, | |
| }, | |
| stores: { | |
| $user, | |
| $isAuth, | |
| $isUserUpdating, | |
| }, | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment