Skip to content
This repository has been archived by the owner on Jul 6, 2024. It is now read-only.

Commit

Permalink
Merge branch 'main' into info-page
Browse files Browse the repository at this point in the history
  • Loading branch information
cbh778899 committed Jun 29, 2024
2 parents 42f1def + bbb5db1 commit 7bee55d
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 6 deletions.
8 changes: 7 additions & 1 deletion components/Layout/header/UserMenuBeforeLogin.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,15 @@ import { emailRule, notEmptyRule, testRules } from '~/tools/inputRules';
})
const isRegister = ref(false);
const keepLogin = ref(false);
const keepLogin = ref(!!savedLoginInfo);
const showPassword = ref(false);
watch(keepLogin, keepLoginOption => {
if(!keepLoginOption) {
localStorage.removeItem('user-login-info');
}
})
function submitForm() {
const { username, email, password } = authDetails.value;
// test if username and password are valid
Expand Down
1 change: 1 addition & 0 deletions components/Layout/header/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import UserMenuBeforeLogin from './UserMenuBeforeLogin.vue';
import UserMenuAfterLogin from './UserMenuAfterLogin.vue';
const user = useUser();
user.requestUpdateUserInfo()
</script>

<template>
Expand Down
4 changes: 2 additions & 2 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ export default defineNuxtConfig({
// },
devProxy: {
"/api": {
// target: "http://localhost:8001/api", // 这里是接口地址
target: "http://198.13.60.170:8001/api", // 这里是接口地址
target: "http://localhost:8001/api", // 这里是接口地址
// target: "http://198.13.60.170:8001/api", // 这里是接口地址
// target: "http://108.160.140.213:8001/api", // 这里是接口地址
changeOrigin: true,
},
Expand Down
6 changes: 4 additions & 2 deletions store/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const useUser = defineStore('user', {
actions: {
requestUpdateUserInfo(info?:object, callback?:Function) {
const setLogin = () => {
new Cookies(null).set('current-user', `${this.userInformation.id}`)
new Cookies(null).set('current-user', {id:this.userInformation.id})
this.isLoggedIn = true;
callback && callback(true);
}
Expand All @@ -39,7 +39,7 @@ const useUser = defineStore('user', {
const currentUser = new Cookies(null).get('current-user')
// if current user is in cookies - means we logged in but somehow lost info, e.g. refreshed page
if(currentUser) {
this.userInformation.id = JSON.parse(currentUser).id
this.userInformation.id = currentUser.id
}
// callback false status and return
else {
Expand Down Expand Up @@ -68,6 +68,7 @@ const useUser = defineStore('user', {

// request for login or register
const { id, authorizedAccount, detail } = await request(`/auth/${reqType}`, {
method: 'POST',
body: (
reqType === 'signin' ?
{ username, password } : { username, email, password }
Expand Down Expand Up @@ -98,6 +99,7 @@ const useUser = defineStore('user', {
},
logoutUser() {
this.isLoggedIn = false;
new Cookies(null).remove('current-user');
this.userInformation = { id: null } as userInfo;
}
}
Expand Down
2 changes: 1 addition & 1 deletion tools/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default (url: string, options?: Options, isEmptyHeader?: boolean) => {
method: 'GET'
}:{
method: "GET",
'Content-Type': 'application/json'
headers: {'Content-Type': 'application/json'}
}
const body =
(typeof options?.body === 'object' && !(options.body instanceof FormData)) ?
Expand Down

0 comments on commit 7bee55d

Please sign in to comment.