Skip to content

Commit

Permalink
feat: login set music_u
Browse files Browse the repository at this point in the history
  • Loading branch information
hawtim committed Oct 31, 2020
1 parent 8c17b70 commit 6663d00
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/utils/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,19 @@ export function isUsernameLoggedIn() {
export function isLooseLoggedIn() {
return isAccountLoggedIn() || isUsernameLoggedIn();
}

export function getMusicU(string) {
const temp = string.split(';')
if (!temp.length) {
return undefined
}
const MUSIC_U = temp.find(item => item.includes('MUSIC_U'))
if (MUSIC_U) {
return MUSIC_U.split('=')[1]
}
return ''
}

export function setMusicU(key, value) {
return Cookies.set(key, value)
}
5 changes: 5 additions & 0 deletions src/views/loginAccount.vue
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ import { loginWithPhone, loginWithEmail } from "@/api/auth";
import md5 from "crypto-js/md5";
import { mapMutations } from "vuex";
import { userPlaylist } from "@/api/user";
import { getMusicU, setMusicU } from '@/utils/auth';
export default {
name: "Login",
Expand Down Expand Up @@ -177,6 +178,10 @@ export default {
md5_password: md5(this.password).toString(),
})
.then((data) => {
// 获取接口返回的 MUSIC_U 写进本地 cookie 解决登录时跳转的问题
// 但是仍然无法完全模拟登录状态,像喜欢歌曲和喜欢列表都会遇到 301 需要登录问题
const MUSIC_U = getMusicU(data.cookie)
setMusicU('MUSIC_U', MUSIC_U)
if (data.code !== 502) {
this.updateData({ key: "user", value: data.profile });
this.afterLogin();
Expand Down

0 comments on commit 6663d00

Please sign in to comment.