【问题标题】:Using Firebase, React and Server Side Rendering使用 Firebase、React 和服务器端渲染
【发布时间】:2016-08-12 15:09:51
【问题描述】:

我正在构建一个带有 react 和 firebase 的项目,以及一个 node express 服务器。处理需要检索用户身份验证状态的路由的最佳方法是什么?如果我理解正确,firebase 不会将其身份验证数据存储在 cookie 中,所以我不确定我是否能够知道登录用户,或者即使用户在服务器上完全登录。

【问题讨论】:

  • 所以我看到了来自 Google IO 的更新。通过正在发布的身份验证更改,这个问题是否更容易解决?
  • Firebase 仅提供类似 CDN 的静态托管环境。它不为您提供用于服务器端渲染的服务器。

标签: firebase


【解决方案1】:

如果您使用的是 firebase 客户端,只需使用 firebase Js 库即可。您可以使用 id 令牌让您的服务器知道使用情况。

【讨论】:

    【解决方案2】:

    我对 React Redux 的体验是,一切都存储在状态中。当您登录时,它将其存储在状态中并从 Actions 传递到 Reducers 到组件。

    动作:

    export function login(email,password){
        return dispatch => auth.signInWithEmailAndPassword(email, password);
    }
    
    export function logout(){
        return dispatch => auth.signOut();
    }
    
    export function createAccount(email, password){
        return dispatch => auth.createUserWithEmailAndPassword(email, password);
    }
    

    【讨论】:

      猜你喜欢
      • 2016-10-12
      • 1970-01-01
      • 2016-03-26
      • 2019-08-07
      • 2020-04-22
      • 1970-01-01
      • 2015-04-19
      • 2015-08-18
      • 2020-06-29
      相关资源
      最近更新 更多