u
This commit is contained in:
30
src/components/AuthBootstrap.jsx
Normal file
30
src/components/AuthBootstrap.jsx
Normal file
@@ -0,0 +1,30 @@
|
||||
import { Component } from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
import { enqueueSnackbar } from 'notistack';
|
||||
import { bootstrapSession } from '../store/authSlice';
|
||||
|
||||
class AuthBootstrap extends Component {
|
||||
componentDidMount() {
|
||||
this.props
|
||||
.bootstrapSession()
|
||||
.unwrap()
|
||||
.then((session) => {
|
||||
if (session.forbidden) {
|
||||
enqueueSnackbar(session.message, { variant: 'warning' });
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
enqueueSnackbar(`Session check failed: ${err.message}`, { variant: 'error' });
|
||||
});
|
||||
}
|
||||
|
||||
render() {
|
||||
return this.props.children;
|
||||
}
|
||||
}
|
||||
|
||||
const mapDispatchToProps = (dispatch) => ({
|
||||
bootstrapSession: () => dispatch(bootstrapSession()),
|
||||
});
|
||||
|
||||
export default connect(null, mapDispatchToProps)(AuthBootstrap);
|
||||
Reference in New Issue
Block a user