uni-app新建用户登录 this.$uniIdPagesStore.store.userInfo 获取的userInfo 不对

uni-app新建用户登录 this.$uniIdPagesStore.store.userInfo 获取的userInfo 不对

错误提示

admin账户登录没有问题,新建用户(选择应用),登录 右上角的用户按钮不显示,但可以进入系统,

查看控制台发现如下错误提示:

Uncaught (in promise) Error: 权限校验未通过,请参考文档:https://uniapp.dcloud.net.cn/uniCloud/schema.html#handler-permission-error _callee$ store.js:57 tryCatch chunk-vendors.js:7930 makeInvokeMethod chunk-vendors.js:8011 defineIteratorMethods chunk-vendors.js:7955 asyncGeneratorStep chunk-vendors.js:8384 _throw chunk-vendors.js:8406 (异步:promise callback) asyncGeneratorStep chunk-vendors.js:8393 _next chunk-vendors.js:8403 _asyncToGenerator chunk-vendors.js:8408 _asyncToGenerator chunk-vendors.js:8400 updateUserInfo store.js:57 loginSuccess store.js:142 loginSuccess login-page.mixin.js:87 pwdLogin login-withpwd.vue:140 (异步:promise callback) pwdLogin login-withpwd.vue:139 click uni_modules-uni-id-pages-pages-login-login-withpwd.js:189


是哪里设置不对,还是bug?

更多关于uni-app新建用户登录 this.$uniIdPagesStore.store.userInfo 获取的userInfo 不对的实战教程也可以访问 https://www.itying.com/category-93-b0.html

1 回复

更多关于uni-app新建用户登录 this.$uniIdPagesStore.store.userInfo 获取的userInfo 不对的实战教程也可以访问 https://www.itying.com/category-93-b0.html


在uni-app中,使用uni-id进行用户登录时,如果通过this.$uniIdPagesStore.store.userInfo获取的userInfo不正确,可能是由于多种原因导致的。这里提供一个较为完整的示例代码,包括登录流程和处理用户信息的部分,帮助你排查问题。

首先,确保你已经正确配置了uni-id,并在项目中引入了相关的依赖。

1. 配置uni-id

确保在manifest.json中已启用uni-id服务,并配置好相关参数。

2. 登录页面代码示例

<template>
  <view>
    <input v-model="username" placeholder="用户名" />
    <input type="password" v-model="password" placeholder="密码" />
    <button @click="login">登录</button>
  </view>
</template>

<script>
export default {
  data() {
    return {
      username: '',
      password: ''
    };
  },
  methods: {
    async login() {
      try {
        const result = await uni.login({
          provider: 'uni-id',
          type: 'login',
          tempAccount: this.username, // 假设使用用户名作为临时账号
          password: this.password
        });

        if (result.code === 0) {
          // 登录成功,获取用户信息
          const userInfo = this.$uniIdPagesStore.store.userInfo;
          console.log('登录成功,用户信息:', userInfo);
          
          // 在这里可以根据需要处理用户信息,比如存储token、用户id等
        } else {
          console.error('登录失败:', result.msg);
        }
      } catch (error) {
        console.error('登录过程中发生错误:', error);
      }
    }
  }
};
</script>

3. 检查和调试

  • 确保uni-id服务正常:检查后端uni-id服务是否运行正常,以及数据库连接等配置是否正确。
  • 检查登录参数:确认传递给uni.login的参数是否正确,特别是tempAccountpassword
  • 控制台输出:在登录成功后,通过console.log输出this.$uniIdPagesStore.store.userInfo,检查其内容是否符合预期。
  • 异步处理:由于登录是异步操作,确保在获取userInfo之前登录流程已经完成。

如果以上步骤都无法解决问题,可能需要进一步检查uni-id的配置或查看uni-app和uni-id的官方文档,以获取更多关于登录和用户信息管理的详细信息。同时,也可以考虑在开发者社区或官方论坛寻求帮助。

回到顶部