提交 bc3dcf06 编写于 作者: DCloud_JSON's avatar DCloud_JSON

- 新增逻辑:调用uni-id-cf的logout接口后刷新设备信息中token的有效期 -...

- 新增逻辑:调用uni-id-cf的logout接口后刷新设备信息中token的有效期 - 修复某些情况下前端执行logout没调用uniID.logout的问题 - 修复某些情况下报push_clientid未定义的问题
上级 f6647360
## 1.1.30(2022-01-26)
- 新增逻辑:调用uni-id-cf的logout接口后刷新设备信息中token的有效期
- 修复某些情况下前端执行logout没调用uniID.logout的问题
- 修复某些情况下报push_clientid未定义的问题
## 1.1.29(2022-01-25)
- 保存`uni_id_token``storage`改用异步方法,方便通过拦截器执行`token`更新后的操作
- 新增通过拦截器监听`uni_id_token`更新,调用云函数刷新刷新设备信息token有效期的API `renewDeviceTokenExpired`
......
......@@ -119,17 +119,30 @@ export default async function() {
if (args.data && args.key == 'uni_id_token') {
let oldToken = uni.getStorageSync('uni_id_token')
if(oldToken.length){
console.log('监听到token更新,就刷新push_clientid的有效期');
uniCloud.callFunction({
name:'uni-id-cf',
data:{
"action": "renewDeviceTokenExpiredxpired",
"params": {push_clientid}
},
complete: (e) => {
console.log(e);
}
})
console.log('监听到token更新,就刷新push_clientid的有效期');
// #ifdef APP-PLUS
let push_clientid;
try {
push_clientid = plus.push.getClientInfo().clientid
} catch (e) {
uni.showModal({
content: '获取推送标识失败。如果你的应用不需要推送功能,请注释掉本代码块',
showCancel: false,
confirmText: "好的"
});
console.log(e)
}
uniCloud.callFunction({
name:'uni-id-cf',
data:{
"action": "renewDeviceTokenExpiredxpired",
"params": {push_clientid}
},
complete: (e) => {
console.log(e);
}
})
// #endif
}
}
// console.log('interceptor-complete', args)
......@@ -475,8 +488,7 @@ async function getDeviceInfo() {
idfa = plus.storage.getItem('idfa') || '', //idfa有需要的用户在应用首次启动时自己获取存储到storage中
vendor = plus.device.vendor;
try {
deviceInfo.push_clientid = uni.getStorageSync('cid') //先都走在线
// deviceInfo.push_clientid = plus.push.getClientInfo().clientid
deviceInfo.push_clientid = plus.push.getClientInfo().clientid
} catch (e) {
uni.showModal({
content: '获取推送标识失败。如果你的应用不需要推送功能,请注释掉本代码块',
......@@ -492,8 +504,5 @@ async function getDeviceInfo() {
vendor
});
// #endif
// #ifndef APP-PLUS
deviceInfo.push_clientid = uni.getStorageSync('cid')
// #endif
return deviceInfo
}
\ No newline at end of file
{
"id": "uni-starter",
"displayName": "uni-starter",
"version": "1.1.29",
"version": "1.1.30",
"description": "云端一体应用快速开发基本项目模版",
"keywords": [
"login",
......
......@@ -23,7 +23,7 @@
<script>
import {
mapMutations
mapActions
} from 'vuex';
export default {
data() {
......@@ -37,7 +37,7 @@
})
},
methods: {
...mapMutations({
...mapActions({
logout: 'user/logout'
}),
cancel(){
......
......@@ -34,7 +34,8 @@
import pushServer from './dc-push/push.js';
import {
mapMutations,
mapGetters
mapGetters,
mapActions
} from 'vuex';
export default {
data() {
......@@ -81,9 +82,9 @@
//#endif
},
methods: {
...mapMutations({
...mapActions({
logout: 'user/logout'
}),
}),
toEdit() {
uni.navigateTo({
url: '/pages/ucenter/userinfo/userinfo'
......@@ -188,19 +189,8 @@
confirmText: this.$t('settings.confirmText'),
success: res => {
if (res.confirm) {
uni.showLoading({
mask: true
});
uniCloud.callFunction({
name:'uni-id-cf',
data:{action:'logout'},
complete: (e) => {
console.log(e);
this.logout();
uni.hideLoading()
uni.navigateBack();
}
})
this.logout()
uni.navigateBack();
}
},
fail: () => {},
......
......@@ -44,7 +44,18 @@ let state = {
}
},
actions = {
logout(context){
uni.showLoading({mask:true})
uniCloud.callFunction({
name:'uni-id-cf',
data:{action:'logout'},
complete: (e) => {
console.log(e);
context.commit('logout')
uni.hideLoading()
}
})
}
}
export default {
namespaced: true,
......
## 1.0.13(2022-01-26)
新增逻辑:调用logout接口后刷新设备信息中token的有效期
## 1.0.12(2022-01-24)
- 优化设备信息存储逻辑
- 新增刷新设备信息token有效期的API `renewDeviceTokenExpired`
......
{
"id": "uni-id-cf",
"displayName": "uni-id-cf",
"version": "1.0.12",
"version": "1.0.13",
"description": "封装uni-id常用接口的云函数,快速实现简单、统一、可扩展的用户管理功能",
"keywords": [
"uni-id-cf",
......
......@@ -114,16 +114,16 @@ exports.main = async (event, context) => {
console.log(context.DEVICEID);
//避免重复新增设备信息,先判断是否已存在
let getDeviceRes = await deviceDB.where({
device_id: context.DEVICEID
"device_id": context.DEVICEID
}).get()
if (getDeviceRes.data.length == 0) {
await addDeviceInfo(res)
} else {
await deviceDB.where({
device_id: context.DEVICEID,
"device_id": context.DEVICEID,
}).update({
...deviceInfo,
tokenExpired: res.tokenExpired,
"tokenExpired": res.tokenExpired,
"user_id": res.uid,
"device_id": context.DEVICEID,
"ua": context.CLIENTUA,
......@@ -179,16 +179,14 @@ exports.main = async (event, context) => {
let res = {}
switch (action) { //根据action的值执行对应的操作
case 'renewDeviceTokenExpired':
let aa = await deviceDB.where({
user_id: params.uid,
return await deviceDB.where({
"user_id": params.uid,
"device_id": context.DEVICEID
}).update({
user_id: params.uid,
push_clientid: params.push_clientid,
"user_id": params.uid,
"push_clientid": params.push_clientid,
tokenExpired
})
console.log(aa);
return aa
break;
case 'refreshSessionKey':
let getSessionKey = await uniID.code2SessionWeixin({
......@@ -397,7 +395,12 @@ exports.main = async (event, context) => {
res = await uniID.checkToken(uniIdToken);
break;
case 'logout':
res = await uniID.logout(uniIdToken)
res = await uniID.logout(uniIdToken)
await deviceDB.where({
"device_id": context.DEVICEID,
}).update({
"tokenExpired": Date.now()
})
break;
case 'sendSmsCode':
/* -开始- 测试期间,为节约资源。统一虚拟短信验证码为: 123456;开启以下代码块即可 */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册