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