简体   繁体   English

如何使用js(节点)限制对某些页面(管理员)的访问?

[英]How can I limit access to certain pages (admin) with js (node?)

I've built a page for my business 我已经为我的业务建立了一个页面

http://www.dishcafecatering.com http://www.dishcafecatering.com

I want to build a page off the main page so I can update the specials each day. 我想从主页上建立一个页面,以便每天更新特价商品。 Is this something that can be done in Vanilla js or will I need to use node or for that matter can I use firebase? 这是可以在Vanilla js中完成的事情,还是我需要使用node,或者可以使用firebase? I don't want everyone to come to the site to have to be authenticated, but maybe just when they click on the admin link? 我不希望每个人都必须经过身份验证才能进入该网站,但是也许只是他们单击管理员链接时才可以? Is there a way in firebase to check the email against data stored in the dB to see if they should have access? 在Firebase中,有没有一种方法可以对照dB中存储的数据检查电子邮件,以查看它们是否应具有访问权限?

Not specifically looking for the exact answer, but a point in the correct direction. 不是专门寻找确切的答案,而是指向正确的方向。 Since I've already built the site, I don't especially want to recode it all in node and express. 由于我已经构建了站点,所以我特别不想在node和express中重新编码。 I'm also a beginner in node and just an advanced beginner in HTML/CSS/JS. 我还是node的初学者,也是HTML / CSS / JS的高级初学者。

You do not have to use Node just for this purpose. 您不必为此仅使用Node。

  1. Set up an /admin page where the user is greeted by a Login form. 设置一个/admin页面,在该页面中,通过Login表单欢迎用户。
  2. Set up firebase auth for admin with email and password in Firebase auth 在Firebase身份验证中使用电子邮件和密码为管理员设置Firebase身份验证
  3. Authenticate against this admin user setup 根据此管理员用户设置进行身份验证
  4. Setup Firebase security rules for Firestore 为Firestore设置Firebase安全规则

     service cloud { match /databases/{database}/recipes { match /<some_path>/ { allow write: if request.auth.uid != null;; } } } 

    This allows write access only to users who are authenticated. 这仅允许对经过身份验证的用户进行写访问。 If in any case you want authentication for other users, you can check request.auth variable for other identification parameters. 无论如何,如果要对其他用户进行身份验证,则可以检查request.auth变量以获取其他标识参数。

You can find this in docs here: https://firebase.google.com/docs/firestore/security/rules-conditions 您可以在以下文档中找到此文件: https : //firebase.google.com/docs/firestore/security/rules-conditions

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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