简体   繁体   English

在ember simple auth中将数据保存在browers的localstorage中

[英]Save data in localstorage of browers in ember simple auth

I have used ember-simple-auth for fb login.I am able fetch the fb's access_token and sending the token to my server for exchange of server token.This works fine and and I am able to make my transition to user feed page.But the problem I am facing is for the first time user.I have to show them some onboarding screen before taking them to their feed screen.And from next time I can skip the onboarding process for them. 我已经使用ember-simple-auth进行fb登录。我可以获取fb的access_token并将令牌发送到我的服务器以交换服务器令牌。这样工作正常,我可以转换到用户提要页面。但是我面临的问题是第一次用户。我必须在将它们带到他们的供稿屏幕之前向他们展示一些入职屏幕。从下次我可以跳过他们的入职流程。

torii.js torii.js

export default Torii.extend({
  torii: service('torii'),

  authenticate() {
    return new RSVP.Promise((resolve, reject) => {
      this._super(...arguments).then((data) => {
        console.log(data.accessToken);
        raw({
          url:      'http://example.co.in/api/socialsignup/',
          type:     'POST',
          dataType: 'json',
          data:     { 'access_token':data.accessToken,'provider':'facebook'}
        }).then((response) => {
          console.log(response.token);
          resolve({
            // jscs:disable requireCamelCaseOrUpperCaseIdentifiers
            access_token: response.token,
            // jscs:enable requireCamelCaseOrUpperCaseIdentifiers
            provider: data.provider
          });
        }, reject);
      }, reject);
    });
  }
});

The response for I am getting from my server is something like this. 我从服务器获得的响应是​​这样的。

For First Time User. 对于初次使用者。

{access_token:'abcd...',signup_done:false}

When Signup_done is false I have to show user the onboarding screen and the make a POST request to server " http://example.co.in/api/post/signupdone " 当Signup_done为false时,我必须向用户显示入职者屏幕并向服务器发出POST请求“ http://example.co.in/api/post/signupdone

For normal user 对于普通用户

{access_token:'abcd...',singup_done:true}

This time I have to just move the user to thier the feed screen skipping the onboarding screen. 这次我必须将用户移动到跳过屏幕上的进给屏幕。

I want to save the singup_done from server to my cookie or brower local storage ( not sure ).So that I can use this value in my handlebars,controller,model,component.I am also open to other suggestion to achieve this with simple method.Please use code to example.Thanks in advance. 我想将singup_done从服务器保存到我的cookie或更好的本地存储(不确定)。所以我可以在我的把手,控制器,模型,组件中使用这个值。我也可以通过简单的方法实现这个目的。 。请使用代码示例。提前谢谢。

You can save data in the session's data by just setting it: 您可以通过设置来保存会话数据中的data

this.get('session').set('data.signupDone', true);

That way signupDone will be persisted (also when the session is invalidated). 这样, signupDone将被持久化(同样在会话失效时)。 Of course if the user logs in in another browser that data won't be present anymore so you should probably store the property in a resource on the server side instead. 当然,如果用户在另一个浏览器中登录,数据将不再存在,那么您应该将该属性存储在服务器端的资源中。

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

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