ember.js - ember data findRecord return value is not the expected record -


i starting ember , picking javascript again after few years. have basic question.

i have login page - login route , controller. have setup ember cli mirage endpoint return applicantsinfo data, when calling /applicantsinfo/123

import ember 'ember';   export default ember.controller.extend({    applicantsinforecord: '',    username: '',    password: '',    actions: {      submitauthform() {      const username = this.get('username');      const password = this.get('password');       // call mirage       this.get('store')       .findrecord('applicantsinfo', username)       .then((applicantsinforecord) => {         this.set('applicantsinforecord', applicantsinforecord);         console.log('inside function',applicantsinforecord);           this.transitiontoroute('form-edit');       })       .then((error) => {         console.log('then error happened', error);         this.set('submissionmessage', 'then(error): there error logging in username:', username);       })       .catch((error) => {         console.log('inside catch', error);         this.set('submissionmessage', 'catch(error): there error logging in username:', username);       });     }   } }); 

login.hbs simple username/password fields , submit button calls controller submitauthform() function

login.hbs

  <label>card number</label>   {{input type="text" value=username}}   <label>password</label> {{input type="text" value=password}}  <button class="primary-link" type="submit" {{action 'submitauthform'}}>   submit </button>   

my problem when findrecord call returns value in then() block, gives me ember class

ember inspector screenshot should return me actual applicantinfo record. returned cli mirage

/app/mirage/config.js

this.get('/applicantsinfos/123', () => {  return { applicantsinfo: { "id": 123, "sessionid": 3, "username":   'abc', "salary": '10110', "age": '1100', "password": 'password03' } }  }); 

basically want set returned object applicantsinfo in controller property , transition next page form-edit, retrieve property, using

this.controllerfor('login').get('applicantsinfo') 

so have 2 questions, should not @ applicantsinfo record instead of ember _class variable.

also correct approach call authentication first, if successful, pass sessionid return applicantsinfo record on next page, in route (in model() function) , can make back-end call pull additional customer profile based on sessionid.

please note not asking how write authentication functionality. question can generalized case - first screen's controller makes back-end call, retrieves sessionid returned result, , transitions next page, route page, makes backend call based on sessionid passed previous page's controller.

whenever dealing records in ember, need use getters access attributes themselves. it's normal see class gibberish in console if log record retrieved through ember data (using findrecord, findall, etc).

try console.log(applicantsinforecord.get('username')) , see if expect.

for authentication, think work. hand rolled auth involves login , logout routes , creating user service. had luck ember simple auth. took me while set once it's going, it's awesome handling state.


Comments

Popular posts from this blog

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -

python - Error while using APScheduler: 'NoneType' object has no attribute 'now' -