Skip to content

Commit b47b884

Browse files
committed
15-React Firebase Auth Persistence with Local Storage
1 parent 6188752 commit b47b884

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/components/Session/withAuthentication.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,18 @@ const withAuthentication = Component => {
99
super(props);
1010

1111
this.state = {
12-
authUser: null,
12+
authUser: JSON.parse(localStorage.getItem('authUser')),
1313
};
1414
}
1515

1616
componentDidMount() {
1717
this.listener = this.props.firebase.onAuthUserListener(
1818
authUser => {
19+
localStorage.setItem('authUser', JSON.stringify(authUser));
1920
this.setState({ authUser });
2021
},
2122
() => {
23+
localStorage.removeItem('authUser');
2224
this.setState({ authUser: null });
2325
},
2426
);

0 commit comments

Comments
 (0)