Skip to content

Instantly share code, notes, and snippets.

@jarkin13
Last active February 12, 2020 01:22
Show Gist options
  • Save jarkin13/c362016e923b2a4ba1a521835917045c to your computer and use it in GitHub Desktop.
Save jarkin13/c362016e923b2a4ba1a521835917045c to your computer and use it in GitHub Desktop.
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