37 lines
911 B
JavaScript
37 lines
911 B
JavaScript
import { Component } from 'react';
|
|
import { connect } from 'react-redux';
|
|
import { enqueueSnackbar } from 'notistack';
|
|
import { notifyError } from '../utils/notify';
|
|
import { bootstrapSession as bootstrapSessionThunk } from '../store/authSlice';
|
|
|
|
let sessionBootstrapped = false;
|
|
|
|
class AuthBootstrap extends Component {
|
|
componentDidMount() {
|
|
if (sessionBootstrapped) return;
|
|
sessionBootstrapped = true;
|
|
|
|
this.props
|
|
.bootstrapSession()
|
|
.unwrap()
|
|
.then((session) => {
|
|
if (session.forbidden) {
|
|
enqueueSnackbar(session.message, { variant: 'warning' });
|
|
}
|
|
})
|
|
.catch((err) => {
|
|
notifyError(err);
|
|
});
|
|
}
|
|
|
|
render() {
|
|
return this.props.children;
|
|
}
|
|
}
|
|
|
|
const mapDispatchToProps = (dispatch) => ({
|
|
bootstrapSession: () => dispatch(bootstrapSessionThunk()),
|
|
});
|
|
|
|
export default connect(null, mapDispatchToProps)(AuthBootstrap);
|