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

Login wall via middleware? #41

Open
Quantisan opened this issue Jul 11, 2014 · 1 comment
Open

Login wall via middleware? #41

Quantisan opened this issue Jul 11, 2014 · 1 comment

Comments

@Quantisan
Copy link

What's a recommended way to build a login wall to a Secretary routed app? Currently I'm doing this up top on my routes namespace.

(defn enforce-login []
  "Check authentication of user then redirect to login page if not"
  (when-not (re-seq #"/#/login$" (.-href js/window.location)) ;; not at login page
    (if-let [token (c/get-token)]
      (go-authenticate token)
      (.replace window.location "/#/login"))))

It sort of work but user can still jump into any route if they know the URL. I'm thinking I could wrap each route with a authorisation func first?

(defroute "/foo" [] (auth? (run-foo)))

That's basically a middleware.

Is there middleware for Secretary? If not, could you point me the right way to making one please?

@noprompt
Copy link
Collaborator

You could handle authentication before calling secretary/dispatch! on hash changes.

Is there middleware for Secretary?

No, not built in, but I think it's something worth considering for future versions. What we should probably do is allow secretary/dispatch! to take a handler function so this sort of thing is easier to do.

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