sa-token v1.9.0 has been released, bringing an exciting new feature: same-end mutual exclusion login

What is sa-token?

sa-token is a JavaWeb lightweight authority authentication framework, official website homepage: http://sa-token.dev33.cn/

If you often use Tencent QQ, you will find that its login has the following characteristics: it can be online at the same time on your mobile phone and computer, but you cannot log in to an account on two mobile phones at the same time
. Only single-site login is allowed on the same type of device, and simultaneous online is allowed on different types of devices

How to achieve mutually exclusive login on the same terminal in sa-token?

First, in the configuration file, set allowConcurrentLoginthe configuration to false, and then declare the device identity when calling related interfaces such as login:

Specify device ID login

StpUtil.setLoginId(10001, "PC");	// 指定`账号id`和`设备标识`进行登录

After calling this method to log in, the same device will be offline (different devices will not be affected), and NotLoginExceptionan exception , scene value =-4

Specifies device identity to force logout

StpUtil.logoutByLoginId(10001, "PC");	// 指定`账号id`和`设备标识`进行强制注销 (踢人下线)

If the second parameter is filled with null or not filled, it means that all online accounts of this account id will be kicked offline, and NotLoginExceptionan exception value =-5

Query the currently logged-in device ID

StpUtil.getLoginDevice();	// 指返回当前token的登录设备

id anti-check token

StpUtil.getTokenValueByLoginId(10001, "APP");	// 获取指定loginId指定设备端的tokenValue 

Official website link: http://sa-token.dev33.cn/

Guess you like

Origin blog.csdn.net/shengzhang_/article/details/112294379