# After login i want to set the user id into the local storage

**URL:** <https://forum.ionicframework.com/t/after-login-i-want-to-set-the-user-id-into-the-local-storage/101355>\
**Category:** ionic-v3\
**Created:** [August 9, 2017, 4:43am UTC](https://forum.ionicframework.com/t/after-login-i-want-to-set-the-user-id-into-the-local-storage/101355 "2017-08-09T04:43:24Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![flycoders\_sourav](https://avatars.discourse-cdn.com/v4/letter/f/e47c2d/32.png) [@flycoders\_sourav](https://forum.ionicframework.com/u/flycoders_sourav)\
**Post date:** [August 9, 2017, 4:43am UTC](https://forum.ionicframework.com/t/after-login-i-want-to-set-the-user-id-into-the-local-storage/101355/1 "2017-08-09T04:43:24Z")

</div>

After login i want to set the user id into the local storage.how can i do that? please help me

---

<div class="post-metadata">

**Author:** ![FnnHuman](https://avatars.discourse-cdn.com/v4/letter/f/5f8ce5/32.png) [@FnnHuman](https://forum.ionicframework.com/u/FnnHuman)\
**Post date:** [August 9, 2017, 4:49am UTC](https://forum.ionicframework.com/t/after-login-i-want-to-set-the-user-id-into-the-local-storage/101355/2 "2017-08-09T04:49:58Z")

</div>

have you even checked the docs?

```auto
import { Storage } from '@ionic/storage';

```

```auto
constructor(public storage: Storage)

```

```auto
  setUserId() {
    this.storage.set('userId', this.userId);
  }

```

---

<div class="post-metadata">

**Author:** ![flycoders\_sourav](https://avatars.discourse-cdn.com/v4/letter/f/e47c2d/32.png) [@flycoders\_sourav](https://forum.ionicframework.com/u/flycoders_sourav)\
**Post date:** [August 9, 2017, 4:51am UTC](https://forum.ionicframework.com/t/after-login-i-want-to-set-the-user-id-into-the-local-storage/101355/3 "2017-08-09T04:51:57Z")

</div>

@FnnHuman.i will check.

---

<div class="post-metadata">

**Author:** ![flycoders\_sourav](https://avatars.discourse-cdn.com/v4/letter/f/e47c2d/32.png) [@flycoders\_sourav](https://forum.ionicframework.com/u/flycoders_sourav)\
**Post date:** [August 9, 2017, 4:53am UTC](https://forum.ionicframework.com/t/after-login-i-want-to-set-the-user-id-into-the-local-storage/101355/4 "2017-08-09T04:53:47Z")

</div>

@FnnHuman where called the function setUserId() ?

---

<div class="post-metadata">

**Author:** ![FnnHuman](https://avatars.discourse-cdn.com/v4/letter/f/5f8ce5/32.png) [@FnnHuman](https://forum.ionicframework.com/u/FnnHuman)\
**Post date:** [August 9, 2017, 4:59am UTC](https://forum.ionicframework.com/t/after-login-i-want-to-set-the-user-id-into-the-local-storage/101355/5 "2017-08-09T04:59:43Z")

</div>

if you ask me that you should learn how to code first

---

<div class="post-metadata">

**Author:** ![flycoders\_sourav](https://avatars.discourse-cdn.com/v4/letter/f/e47c2d/32.png) [@flycoders\_sourav](https://forum.ionicframework.com/u/flycoders_sourav)\
**Post date:** [August 9, 2017, 7:07am UTC](https://forum.ionicframework.com/t/after-login-i-want-to-set-the-user-id-into-the-local-storage/101355/6 "2017-08-09T07:07:54Z")

</div>

@FnnHuman how to get the userId from the storage?

---

<div class="post-metadata">

**Author:** ![FnnHuman](https://avatars.discourse-cdn.com/v4/letter/f/5f8ce5/32.png) [@FnnHuman](https://forum.ionicframework.com/u/FnnHuman)\
**Post date:** [August 9, 2017, 7:11am UTC](https://forum.ionicframework.com/t/after-login-i-want-to-set-the-user-id-into-the-local-storage/101355/7 "2017-08-09T07:11:15Z")

</div>

```auto
    this.storage.get('userId').then((val) => {
      console.log(val);
    });

```

---

<div class="post-metadata">

**Author:** ![flycoders\_sourav](https://avatars.discourse-cdn.com/v4/letter/f/e47c2d/32.png) [@flycoders\_sourav](https://forum.ionicframework.com/u/flycoders_sourav)\
**Post date:** [August 9, 2017, 7:15am UTC](https://forum.ionicframework.com/t/after-login-i-want-to-set-the-user-id-into-the-local-storage/101355/8 "2017-08-09T07:15:04Z")

</div>

@FnnHuman Thank you.

---

<div class="post-metadata">

**Author:** ![flycoders\_sourav](https://avatars.discourse-cdn.com/v4/letter/f/e47c2d/32.png) [@flycoders\_sourav](https://forum.ionicframework.com/u/flycoders_sourav)\
**Post date:** [August 9, 2017, 7:22am UTC](https://forum.ionicframework.com/t/after-login-i-want-to-set-the-user-id-into-the-local-storage/101355/9 "2017-08-09T07:22:07Z")

</div>

@FnnHuman when i use the code an try to show userid in alert box.but showing the full. function ![error](https://global.discourse-cdn.com/ionicframework/original/3X/d/5/d5e37443268f253f50f0d86b458283ce508ebc46.PNG)

---

<div class="post-metadata">

**Author:** ![FnnHuman](https://avatars.discourse-cdn.com/v4/letter/f/5f8ce5/32.png) [@FnnHuman](https://forum.ionicframework.com/u/FnnHuman)\
**Post date:** [August 9, 2017, 7:25am UTC](https://forum.ionicframework.com/t/after-login-i-want-to-set-the-user-id-into-the-local-storage/101355/10 "2017-08-09T07:25:12Z")

</div>

what the hell, show me your code

---

<div class="post-metadata">

**Author:** ![flycoders\_sourav](https://avatars.discourse-cdn.com/v4/letter/f/e47c2d/32.png) [@flycoders\_sourav](https://forum.ionicframework.com/u/flycoders_sourav)\
**Post date:** [August 9, 2017, 7:28am UTC](https://forum.ionicframework.com/t/after-login-i-want-to-set-the-user-id-into-the-local-storage/101355/11 "2017-08-09T07:28:54Z")

</div>

below my service provider code  
import { Injectable } from ‘@angular/core’;

import { Events } from ‘ionic-angular’;  
import { Storage } from ‘@ionic/storage’;

@Injectable()  
export class UserData {  
constructor(public events: Events,public storage: Storage) {}  
setUserId(userid: string): void {  
this.storage.set(‘userid’, userid);  
};

getUserid() {  
// Notice that the get method returns a promise!  
this.storage.get(‘userid’).then((value) =\> {  
[//console.log](https://console.log)(userid);  
});  
}  
/_setUserId(): Promise {  
return this.storage.get(‘userid’).then((value) =\> {  
return value;  
});  
};  
};_/  
}  
[//this.userData.setUserId](https://this.userData.setUserId)(this.setUserId);

---

<div class="post-metadata">

**Author:** ![flycoders\_sourav](https://avatars.discourse-cdn.com/v4/letter/f/e47c2d/32.png) [@flycoders\_sourav](https://forum.ionicframework.com/u/flycoders_sourav)\
**Post date:** [August 9, 2017, 7:30am UTC](https://forum.ionicframework.com/t/after-login-i-want-to-set-the-user-id-into-the-local-storage/101355/12 "2017-08-09T07:30:08Z")

</div>

from login.ts try to store userid into the local storage.  
this.userData.setUserId(this.userid);

---

<div class="post-metadata">

**Author:** ![rapropos](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/rapropos/32/100227_2.png) [@rapropos](https://forum.ionicframework.com/u/rapropos)\
**Post date:** [August 9, 2017, 7:36am UTC](https://forum.ionicframework.com/t/after-login-i-want-to-set-the-user-id-into-the-local-storage/101355/13 "2017-08-09T07:36:10Z")

</div>

> [@flycoders\_sourav](#):
>
> // Notice that the get method returns a promise!

No it doesn’t. Your comment is a lie. That method doesn’t return anything, and if you used proper return type declarations instead of false comments, you would have gotten a build-time error informing you of this fact. Please read the TypeScript, Angular, and Ionic documentation thoroughly until you really understand the fundamental building blocks of web apps. You cannot become competent at this by simply copying random nonsense you see on the web and expecting reliable results.

---

<div class="post-metadata">

**Author:** ![flycoders\_sourav](https://avatars.discourse-cdn.com/v4/letter/f/e47c2d/32.png) [@flycoders\_sourav](https://forum.ionicframework.com/u/flycoders_sourav)\
**Post date:** [August 9, 2017, 7:38am UTC](https://forum.ionicframework.com/t/after-login-i-want-to-set-the-user-id-into-the-local-storage/101355/14 "2017-08-09T07:38:40Z")

</div>

@rapropos sorry for that.

---

<div class="post-metadata">

**Author:** ![flycoders\_sourav](https://avatars.discourse-cdn.com/v4/letter/f/e47c2d/32.png) [@flycoders\_sourav](https://forum.ionicframework.com/u/flycoders_sourav)\
**Post date:** [August 9, 2017, 7:40am UTC](https://forum.ionicframework.com/t/after-login-i-want-to-set-the-user-id-into-the-local-storage/101355/15 "2017-08-09T07:40:45Z")

</div>

@rapropos can i upload my full code?

---

<div class="post-metadata">

**Author:** ![rapropos](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/rapropos/32/100227_2.png) [@rapropos](https://forum.ionicframework.com/u/rapropos)\
**Post date:** [August 9, 2017, 7:41am UTC](https://forum.ionicframework.com/t/after-login-i-want-to-set-the-user-id-into-the-local-storage/101355/16 "2017-08-09T07:41:58Z")

</div>

I don’t intend it as a personal attack, but in order for other people in forums like this to be able to give you assistance in a productive manner, you need to build up core competence in your craft, assuming that you really have a passion for programming.

---

<div class="post-metadata">

**Author:** ![flycoders\_sourav](https://avatars.discourse-cdn.com/v4/letter/f/e47c2d/32.png) [@flycoders\_sourav](https://forum.ionicframework.com/u/flycoders_sourav)\
**Post date:** [August 9, 2017, 7:50am UTC](https://forum.ionicframework.com/t/after-login-i-want-to-set-the-user-id-into-the-local-storage/101355/17 "2017-08-09T07:50:54Z")

</div>

@rapropos Thanks for you valuable advice.
