Skip to content

Commit

Permalink
fix for async-labs#444 issue
Browse files Browse the repository at this point in the history
  • Loading branch information
tima101 committed Feb 13, 2021
1 parent 24829c2 commit a345cbd
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
10 changes: 5 additions & 5 deletions book/3-end/lib/withAuth.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default function withAuth(
class App extends React.Component {
static async getInitialProps(ctx) {
const isFromServer = typeof window === 'undefined';
const user = ctx.req ? ctx.req.user && ctx.req.user.toObject() : globalUser;
const user = ctx.query ? ctx.req.user && ctx.req.user.toObject() : globalUser;

if (isFromServer && user) {
user._id = user._id.toString();
Expand All @@ -45,10 +45,10 @@ export default function withAuth(
globalUser = user;
}

if (loginRequired && !logoutRequired && !user) {
Router.push('/login');
return;
}
// if (loginRequired && !logoutRequired && !user) {
// Router.push('/login');
// return;
// }

if (logoutRequired && user) {
Router.push('/');
Expand Down
2 changes: 1 addition & 1 deletion book/3-end/pages/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ class Index extends React.Component {
Index.propTypes = propTypes;
Index.defaultProps = defaultProps;

export default withAuth(Index, { loginRequired: true });
export default withAuth(Index);
4 changes: 3 additions & 1 deletion book/3-end/server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const next = require('next');
const mongoose = require('mongoose');

const setupGoogle = require('./google');
const User = require('./models/User');

require('dotenv').config();

Expand Down Expand Up @@ -51,7 +52,8 @@ app.prepare().then(() => {

// server.get('/', async (req, res) => {
// const user = await User.findOne({ slug: 'team-builder-book' });
// app.render(req, res, '/', { user });
// req.user = user;
// app.render(req, res, '/');
// });

setupGoogle({ server, ROOT_URL });
Expand Down

0 comments on commit a345cbd

Please sign in to comment.