Skip to content

Commit

Permalink
Optimize: login
Browse files Browse the repository at this point in the history
  • Loading branch information
LazyCreeper committed Oct 24, 2023
1 parent adc4f8b commit ac76ffe
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 25 deletions.
24 changes: 1 addition & 23 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,10 @@
import { onMounted } from "vue";
import Header from "./components/Header.vue";
import { RouterView } from "vue-router";
import { ElNotification } from "element-plus";
import { userStore } from "@/stores/user";
import { roomStore } from "@/stores/room";
import { userInfo as userInfoApi } from "@/services/apis/auth";
const { state: userInfo_, execute: reqUserInfo } = userInfoApi();
const userState = userStore();
const initApp = async () => {
try {
await reqUserInfo({
headers: {
Authorization: localStorage.getItem("userToken") || ""
}
});
if (userInfo_.value) {
userState.userInfo = userInfo_.value;
roomStore().login = true;
}
} catch (err: any) {
console.error(err);
}
};
onMounted(() => {
initApp();
if (localStorage.getItem("userToken")) return (roomStore().login = true);
});
</script>

Expand Down
2 changes: 1 addition & 1 deletion src/views/CreateRoom.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const operateRoom = async () => {
savePwd.value && localStorage.setItem("password", formData.value.password);
router.replace(`/${createRoomInfo.value.roomId}/cinema`);
router.replace(`/cinema/${createRoomInfo.value.roomId}`);
} catch (err: any) {
console.error(err);
ElNotification({
Expand Down
2 changes: 1 addition & 1 deletion src/views/JoinRoom.vue
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const JoinRoom = async () => {
savePwd.value && localStorage.setItem("password", formData.value.password);
router.replace(`/${joinRoomInfo.value.roomId}/cinema`);
router.replace(`/cinema/${joinRoomInfo.value.roomId}`);
} catch (err: any) {
console.error(err);
ElNotification({
Expand Down
4 changes: 4 additions & 0 deletions src/views/oAuth2/callback.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ const getUserInfo = async () => {
isLoading.value = false;
localStorage.setItem("uname", state.value.username);
room.login = true;
ElNotification({
title: "登录成功",
type: "success"
});
router.push("/");
}
} catch (err: any) {
Expand Down

0 comments on commit ac76ffe

Please sign in to comment.