Last active
February 12, 2020 01:22
-
-
Save jarkin13/c362016e923b2a4ba1a521835917045c 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
function UserProvider({ children }) { | |
... | |
Hub.listen('auth', (data) => { | |
const { payload } = data; | |
console.log('A new auth event has happened: ', data) | |
if (payload.event === 'signIn') { | |
setImmediate(() => dispatch({ type: "SET_USER", user: payload })); | |
// Make an API call here to check if user has logged in | |
// API.graphql(graphqlOperation(checkFirstTime(userID)); | |
// if no record found, set a record in the DB | |
// API.graphql(graphqlOperation(logUser, input:{ | |
// id: userID | |
// })); | |
} | |
if (payload.event === 'signOut') { | |
setTimeout(() => dispatch({ type: "UNAUTHORIZE" }), 350); | |
} | |
}); | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment