fix: 修复登录拒绝也存token

This commit is contained in:
duanshuwen
2025-09-25 19:11:42 +08:00
parent 86c87b2cc4
commit f3d84c9349
4 changed files with 21 additions and 13 deletions

View File

@@ -1,4 +1,4 @@
export const getWeChatAuthCode = () => {
export const getWeChatAuthCode = (e) => {
return new Promise((resolve, reject) => {
// 条件编译微信小程序、抖音小程序
let provider = "";
@@ -10,10 +10,16 @@ export const getWeChatAuthCode = () => {
provider = "toutiao";
// #endif
// 判断用户拒绝授权
if (e.detail.errMsg === "getPhoneNumber:fail user deny") {
reject();
return;
}
uni.login({
provider,
onlyAuthorize: true,
success: (res) => {
console.log("微信登录成功", res);
resolve(res.code);
},
fail: (err) => {

View File

@@ -8,13 +8,13 @@ import { useAppStore } from "@/store";
import { clientId } from "@/constant/base";
import { NOTICE_EVENT_LOGIN_SUCCESS } from "@/constant/constant";
const loginAuth = () => {
const loginAuth = (e) => {
uni.setStorageSync("token", "");
const appStore = useAppStore();
appStore.setHasToken(false);
return new Promise(async (resolve, reject) => {
const openIdCode = await getWeChatAuthCode();
const openIdCode = await getWeChatAuthCode(e);
console.log("获取到的微信授权code:", openIdCode);
const params = {
openIdCode: [openIdCode],