简体   繁体   English

应用程序重定向到另一个应用程序Meteor JS时注销用户

[英]Logout user when app redirect to another app Meteor JS

I have 2 apps, one for auth while the other for products. 我有2个应用程序,一个用于auth,另一个用于产品。 After login or verification of email, the user is redirected to the products app. 登录或验证电子邮件后,用户将被重定向到产品应用程序。 On redirection, the recently logged in user is instantly logged out, so a reference to the logged in user becomes null , and I'll need the logged in credentials in the auth app to authenticate on the second. 重定向时,最近登录的用户会立即注销,因此对已登录用户的引用将变为null ,并且我将需要auth应用中的已登录凭据进行第二次身份验证。 How do I maintain the logged in state in the auth app when it has redirected to the products app? 重定向到产品应用程序后,如何在身份验证应用程序中保持登录状态?

This is the login function on the auth app 这是auth应用程序上的登录功能

var callLogin = function (email, password, router) {
    Meteor.loginWithPassword(email, password, ( error )=> {
        if (error) {
            sAlert.error( error );
        } else {
            sAlert.success("Logged in successfully");
             window.location.replace( "http://localhost:3300/" + Meteor.userId() );
        } 
    });
}

This is the onCreated function on the products app 这是产品应用程序上的onCreated函数

Tracker.autorun(function () {

        let router = FlowRouter.getParam("_id");
        let AuthConnection = DDP.connect( AuthURL );

         if ( AuthConnection ) {
            console.log( router );
            AuthConnection.call('logins.user', router, ( error, response )=> {
                if ( error ) {
                    console.log( error );
                } console.log( response );
            } );
        }
      });

The logged in user is always present until the redirection that it becomes null. 在重定向为空之前,登录用户始终存在。 What do I do to maintain the logged in state of the user in the auth app? 如何维护身份验证应用程序中用户的登录状态?

I assume both apps connect to the same database? 我假设两个应用程序都连接到同一个数据库?

When you redirect your local state changes - specifically in this case your local storage state which tracks user resume tokens. 当您重定向本地状态更改时-特别是在这种情况下,您的本地存储状态会跟踪用户恢复令牌。

If you want to allow one app to authenticate for another you need some form of SSO - a trivial implementation would be after login to request a resumeToken from the server, pass that to your second app in the URL, then use Meteor.loginWithToken . 如果要允许一个应用程序对另一个应用程序进行身份验证,则需要某种形式的SSO-在登录后从服务器请求一个resumeToken的简单实现,将其传递给URL中的第二个应用程序,然后使用Meteor.loginWithToken A more hacky (but maybe simpler?) way might be to copy the token saved in localStorage from app1, pass it in the URL to app2 then use save it there too. 一种更狡猾(但可能更简单?)的方法可能是从app1复制保存在localStorage中的令牌,将其传递到URL中到app2,然后再在此处使用保存。

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

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