Skip to content

Commit

Permalink
authorization_required
Browse files Browse the repository at this point in the history
  • Loading branch information
1aerostorm committed Apr 24, 2024
1 parent deb908a commit abdf46d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
4 changes: 2 additions & 2 deletions app/components/modules/Modals.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Modals extends React.Component {
this.shouldComponentUpdate = shouldComponentUpdate(this, 'Modals');
}

onLoginBackdropClick = (e) => {
onLoginTryClose = (e) => {
const { loginUnclosable } = this.props;
if (loginUnclosable)
throw new Error('Closing login modal is forbidden here');
Expand Down Expand Up @@ -86,7 +86,7 @@ class Modals extends React.Component {

return (
<div>
{show_login_modal && <Reveal onBackdropClick={this.onLoginBackdropClick} onHide={hideLogin} show={show_login_modal}>
{show_login_modal && <Reveal onBackdropClick={this.onLoginTryClose} onEscapeKeyDown={this.onLoginTryClose} onHide={hideLogin} show={show_login_modal}>
<LoginForm onCancel={hideLogin} />
</Reveal>}
{show_confirm_modal && <Reveal onHide={hideConfirm} show={show_confirm_modal}>
Expand Down
13 changes: 13 additions & 0 deletions app/redux/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@ export default createModule({
name: 'user',
initialState: defaultState,
transformations: [
{
action: 'REQUIRE_LOGIN',
reducer: (state, {payload}) => {
console.log('ACT-----')
return state.merge({
show_login_modal: true,
loginDefault: {
unclosable: true,
cancelIsRegister: true
}
})
}
},
{
action: 'SHOW_LOGIN',
reducer: (state, {payload}) => {
Expand Down
13 changes: 12 additions & 1 deletion shared/UniversalRender.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,23 @@ import {
match,
applyRouterMiddleware
} from 'react-router';
import * as api from 'app/utils/APIWrapper'
import { Provider } from 'react-redux';
import RootRoute from 'app/RootRoute';
import {createStore, applyMiddleware, compose} from 'redux';
import { browserHistory } from 'react-router';
import { useScroll } from 'react-router-scroll';
import createSagaMiddleware from 'redux-saga';
import { syncHistoryWithStore } from 'react-router-redux';

import * as api from 'app/utils/APIWrapper'
import rootReducer from 'app/redux/RootReducer';
import rootSaga from 'app/redux/RootSaga';
import {component as NotFound} from 'app/components/pages/NotFound';
import extractMeta from 'app/utils/ExtractMeta';
import Translator from 'app/Translator';
import getState from 'app/utils/StateBuilder';
import {routeRegex} from "app/ResolveRoute";
import session from 'app/utils/session'
import {contentStats} from 'app/utils/StateFunctions'
import {APP_NAME, SEO_TITLE} from 'app/client_config';
import constants from 'app/redux/constants';
Expand Down Expand Up @@ -80,6 +82,9 @@ export async function serverRender({

if (process.env.BROWSER) {
const store = createStore(rootReducer, initial_state, middleware);
if (!session.load().currentName && $STM_Config.authorization_required) {
store.dispatch({type: 'user/REQUIRE_LOGIN', payload: {}});
}
// sagaMiddleware.run(PollDataSaga).done
// .then(() => console.log('PollDataSaga is finished'))
// .catch(err => console.log('PollDataSaga is finished with error', err));
Expand Down Expand Up @@ -161,6 +166,9 @@ export async function serverRender({

offchain.server_location = location;
serverStore = createStore(rootReducer, { global: onchain, offchain});
if (!offchain.account && $STM_Config.authorization_required) {
serverStore.dispatch({type: 'user/REQUIRE_LOGIN', payload: {}});
}
serverStore.dispatch({type: '@@router/LOCATION_CHANGE', payload: {pathname: location}});
// TODO: maybe use request to golosnotify to fetch counters?
/*if (offchain.account) {
Expand Down Expand Up @@ -221,6 +229,9 @@ export async function serverRender({

export function clientRender(initialState) {
const store = createStore(rootReducer, initialState, middleware);
if (!session.load().currentName && $STM_Config.authorization_required) {
store.dispatch({type: 'user/REQUIRE_LOGIN', payload: {}});
}
sagaMiddleware.run(rootSaga)

const history = syncHistoryWithStore(browserHistory, store);
Expand Down

0 comments on commit abdf46d

Please sign in to comment.