简体   繁体   中英

Redirect unauthenticated user to default URL with node.js and angularjs

I have used node.js restify and angularjs to create a web app with no user administration. Now, I would like to add the user administration feature.

Users need to login to gain access to the web app. If they are not authenticated, they will be redirected to a default URL at www.webroot.com/login.html .

I am looking at the right node.js module to implement this feature but am at a loss at the moment. The 2 modules that caught my attention is passport-restify and passport-http .

https://www.npmjs.com/package/passport-restify https://www.npmjs.com/package/passport-http

Here are some questions to implement this feature;

  • Which node.js module can be used to implement this user login feature? What is the difference between the two?

  • Is the actual URL redirecting action done using angularjs or node.js?

What are some sample code examples for user login? So far, I find documentation but few sample codes.

In order to provide a authentication system to the application u need to protect the api server side and also the views i have used this sample

https://scotch.io/tutorials/authenticate-a-node-js-api-with-json-web-tokens

please check this might be usefull

This module restify-ensure-login meets your requirements very well. https://www.npmjs.com/package/restify-ensure-login

This middleware ensures that a user is logged in. If a request is received that is unauthenticated, the request will be redirected to a login page. The URL will be saved in the session, so the user can be conveniently returned to the page that was originally requested.

Since your existing code base is in restify and this module makes use of restify, it is less of a hassle than to make use of most of the examples out there which use Express.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM