Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Protected routes getting called without authentication #126

Open
vineet-287 opened this issue Sep 21, 2017 · 1 comment
Open

Protected routes getting called without authentication #126

vineet-287 opened this issue Sep 21, 2017 · 1 comment

Comments

@vineet-287
Copy link

vineet-287 commented Sep 21, 2017

I got routes are calling without authentication. Even I used protected but it's not working. Here below my snippet :

//in routes.js

import UniversalRouter from 'universal-router';

const routes = [
 path: '/',
  protected : true,
  
  async action() {
    const Home = await new Promise((resolve) => {
      require.ensure([], (require) => {
        resolve(require('./Home').default);
      }, 'home');
    });
    return <Home key={'home'} />;
  },
];
//When router resolve
app.get('*', async (req, res, next) => {
    try {
        let css = new Set();
        let statusCode = 200;
        const data = {title: '', description: '', style: '', script: assets.main.js, children: ''};
        await UniversalRouter.resolve(routes, {
            path: req.path,
            query: req.query,
            context: {
                insertCss: (...styles) => {
                    styles.forEach(style => css.add(style._getCss())); // eslint-disable-line no-underscore-dangle, max-len
                },
                setTitle: value => (data.title = value),
                setMeta: (key, value) => (data[key] = value),
            },
            render(component, status = 200) {
                css = new Set();
                statusCode = status;
                data.children = ReactDOM.renderToString(component);
                data.style = [...css].join('');
                return true;
            },
        });

        const html = ReactDOM.renderToStaticMarkup(<Html {...data} />);

        res.status(statusCode);
        res.send(`<!doctype html>${html}`);
    } catch (err) {
        next(err);
    }
});

Can somebody please explain how to redirect them on login screen ?

@frenzzy
Copy link
Member

frenzzy commented Oct 3, 2017

In your example, it's unclear where the render(component, status) is called from.
In the current version of React Starter Kit you can find an example.

@frenzzy frenzzy mentioned this issue Oct 8, 2017
20 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants