Properties USER change after reload
See original GitHub issueVersion
@nuxtjs/strapi: 0.3.1 nuxt: 2.15.8 with i18n active strapi: 3.6.8 with i18n active
Problem
I have on the “user” types collection add additional fields (sample: avatar type “single media images”) On the website, once connected, I find these additional fields in the user object. If I refresh website, these additional fields disappear.
Steps to reproduce
1- In admin strapi, create field “media” in collection “user” with this propertie:
- base settings: avatar (name), single media (type)
- advanced settings : images (type of media)
2- In website, create a login form who get user info:
const user = await this.$strapi.login({ identifier: this.model.username, password: this.model.password, })
3- In another page of website, I get info of user
this.user = await this.$strapi.user
console.log(this.user)
=> Result of log (OK), I have object “avatar”:
avatar: Object
blocked: false
confirmed: true
created_at: "2021-09-03T09:12:03.889Z"
email: "admin@example.com"
id: 1
initials: "at"
provider: "local"
role: Object
updated_at: "2021-09-08T12:39:39.982Z"
3- Now, I refresh my website with ‘F5’
this.user = await this.$strapi.user
console.log(this.user)
=> Result of log (KO), I loose object “avatar”:
blocked: false
confirmed: true
created_at: "2021-09-03T09:12:03.889Z"
email: "admin@example.com"
id: 1
initials: "at"
provider: "local"
role: Object
updated_at: "2021-09-08T12:39:39.982Z"
username: "admin user test"
But with the another specific field “initials” (type “small text”), I don’t have a problem
Why object “user” loose the field “avatar” after refresh ?
Issue Analytics
- State:
- Created 2 years ago
- Comments:6
Top GitHub Comments
@madsh93 OK thanks a lot I did not see the other request, sorry.
The solution, if anyone needs it:
1- Create file “User.js” in folder: “./extensions/users-permissions/services/”
2- In file “User.js” write this:
module.exports = { async fetchAuthenticatedUser(id) { return strapi .query("user", "users-permissions") .findOne({ id }, ["role", "avatar"]); }, };