为什么angular模板中的app-auth服务注销功能不删除cookie,而是清空cookie?
Why does the app-auth service logout function in the angular template null the cookie instead of delete it?
logout(reload?: boolean): void {
abp.auth.clearToken();
abp.utils.setCookieValue(
AppConsts.authorization.encryptedAuthTokenName,
undefined,
undefined,
abp.appPath
);
if (reload !== false) {
location.href = AppConsts.appBaseUrl;
}
}
为什么使用这段代码而不是 deleteCookie
函数?
没有特别的原因。在 aspnetboilerplate/module-zero-core-template@6cd84d7
.
中已更改为 deleteCookie
deleteCookie(AppConsts.authorization.encryptedAuthTokenName, abp.appPath)
设置类似于 enc_auth_token=; expires=Fri, 23 Apr 2021 00:00:00 GMT; path=/
,其中 Fri, 23 Apr 2021 00:00:00 GMT
是 86400000 毫秒(一天)前。
- 这会导致 cookie 被立即删除。
getCookieValue
会 return null
.
setCookieValue(AppConsts.authorization.encryptedAuthTokenName, undefined, undefined, abp.appPath)
设置类似 enc_auth_token=; path=/
的内容,这是一个会话 cookie。
- 这会导致在会话结束时删除 cookie。
- 在会话结束之前,
getCookieValue
会 return ''
(从 ABP v6.3 开始)。
logout(reload?: boolean): void {
abp.auth.clearToken();
abp.utils.setCookieValue(
AppConsts.authorization.encryptedAuthTokenName,
undefined,
undefined,
abp.appPath
);
if (reload !== false) {
location.href = AppConsts.appBaseUrl;
}
}
为什么使用这段代码而不是 deleteCookie
函数?
没有特别的原因。在 aspnetboilerplate/module-zero-core-template@6cd84d7
.
deleteCookie
deleteCookie(AppConsts.authorization.encryptedAuthTokenName, abp.appPath)
设置类似于 enc_auth_token=; expires=Fri, 23 Apr 2021 00:00:00 GMT; path=/
,其中 Fri, 23 Apr 2021 00:00:00 GMT
是 86400000 毫秒(一天)前。
- 这会导致 cookie 被立即删除。
getCookieValue
会 returnnull
.
setCookieValue(AppConsts.authorization.encryptedAuthTokenName, undefined, undefined, abp.appPath)
设置类似 enc_auth_token=; path=/
的内容,这是一个会话 cookie。
- 这会导致在会话结束时删除 cookie。
- 在会话结束之前,
getCookieValue
会 return''
(从 ABP v6.3 开始)。