Skip to content

Instantly share code, notes, and snippets.

@Franpastoragusti
Last active February 3, 2020 13:47
Show Gist options
  • Save Franpastoragusti/1a8c01000bfe80481b353aadecc7baf8 to your computer and use it in GitHub Desktop.
Save Franpastoragusti/1a8c01000bfe80481b353aadecc7baf8 to your computer and use it in GitHub Desktop.
/* /src/providers/authProvider.jsx */
import React, {Component} from "react";
import AuthService from "../services/authService";
const AuthContext = React.createContext({
signinRedirectCallback: () => ({}),
logout: () => ({}),
signoutRedirectCallback: () => ({}),
isAuthenticated: () => ({}),
signinRedirect: () => ({}),
signinSilentCallback: () => ({}),
createSigninRequest: () => ({})
});
export const AuthConsumer = AuthContext.Consumer;
export class AuthProvider extends Component {
authService;
constructor(props) {
super(props);
this.authService = new AuthService();
}
render() {
return <AuthContext.Provider value={this.authService}>{this.props.children}</AuthContext.Provider>;
}
}
@PurpleMonkeyWrench
Copy link

How would you go about adding Redux to this provider? https://react-redux.js.org/api/provider

Do you wrap the whole AuthProvider in a Redux Provider or do you customize this AuthProvider to use the Redux store.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment