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

Is Curi caching the routes? #77

Closed
mparker11 opened this issue May 31, 2018 · 4 comments
Closed

Is Curi caching the routes? #77

mparker11 opened this issue May 31, 2018 · 4 comments

Comments

@mparker11
Copy link

Related to #74

Scenario:
User logs in and is directed to the next page (page requires authentication)

Problem:
My routes file contains the following function

const protectRoute = (route) => {
    if (!isLoggedIn()) {
        return () => ({ redirectTo: { name: 'Login' } });
    }
    
    return () => ({ body: route });
};

which is placed on all routes where a user is not allowed unless authenticated. The issue is navigating programmatically. If I try to do router.navigate({ name: 'Dashboard' });, I am greeted by this error:

Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.

However, if I refresh the page everything loads fine and I am able to click links to other pages. As I've been debugging, I noticed that when Dashboard is called programmatically, routes.js is never hit again. So I tried placing a debugger on my ReactDOM.hydrate call and it results in this object being passed from the response:

shot_180530_190955

Notice the redirectTo object at the bottom. This means, according to the protectRoute function above, isLoggedIn() is false which returns the redirect. At this point, I'm expecting the routes to be hit in order to determine if the user is logged in (which is true in this case).

Any idea what this could be? Are the routes being "cached" in Curi?

@pshrmn
Copy link
Owner

pshrmn commented May 31, 2018

protectRoute() is only being called initially, where it returns one of two functions based on the initial login state. It should be returning a single function whose output is based on the login state when it is called.

const protectRoute = (route) => {
  return () => {
    if (!isLoggedIn()) {
        return { redirectTo: { name: 'Login' } };
    }    
    return { body: route };
};

Does that make sense?

@mparker11
Copy link
Author

I think I should leave you alone with my trivial problems. Thank you so much! Also, do you have a donation link? I really love this project!

@pshrmn
Copy link
Owner

pshrmn commented May 31, 2018

No donations right now, but I appreciate the thought. If you know anyone else who might find Curi useful, I also appreciate sharing.

I'm pretty close to finally releasing v1.0.0 (at least of the core, react, side effect, and route interaction packages; vue, svelte, and react-native might need some polish), which is exciting.

Side effects are being slightly re-worked to make them safer for React Suspense. Suspense won't release for a while, but I want to make sure that the transition for that is relatively seamless.

@mparker11
Copy link
Author

That's good to know. I'll be looking out for it!

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