feat: request google login while refresh

This commit is contained in:
Tim
2025-07-23 15:49:41 +08:00
parent 33ddc3bb77
commit 7b22b2d15d
5 changed files with 35 additions and 24 deletions

View File

@@ -8,8 +8,9 @@ import './assets/toast.css'
// Use Sugar theme from vue-toast-notification for better toast styling.
// If you prefer Bootstrap style, replace with theme-bootstrap.css instead.
import { useToast } from 'vue-toastification'
import { checkToken, clearToken } from './utils/auth'
import { checkToken, clearToken, isLogin } from './utils/auth'
import { initTheme } from './utils/theme'
import { loginWithGoogle } from './utils/google'
// Configurable API domain and port
// export const API_DOMAIN = 'http://127.0.0.1'
@@ -47,4 +48,10 @@ checkToken().then(valid => {
if (!valid) {
clearToken()
}
if (!isLogin()) {
setTimeout(() => {
loginWithGoogle()
}, 3000)
}
})

View File

@@ -50,3 +50,11 @@ export async function googleSignIn(redirect_success, redirect_not_approved) {
/* ignore */
}
}
export function loginWithGoogle() {
googleSignIn(() => {
this.$router.push('/')
}, (token) => {
this.$router.push('/signup-reason?token=' + token)
})
}

View File

@@ -111,7 +111,7 @@ import { ref, onMounted, watch } from 'vue'
import { useRoute } from 'vue-router'
import { stripMarkdown } from '../utils/markdown'
import { API_BASE_URL } from '../main'
import { getToken } from '../utils/auth'
import { getToken, isLogin } from '../utils/auth'
import TimeManager from '../utils/time'
import CategorySelect from '../components/CategorySelect.vue'
import TagSelect from '../components/TagSelect.vue'
@@ -120,6 +120,7 @@ import ArticleCategory from '../components/ArticleCategory.vue'
import SearchDropdown from '../components/SearchDropdown.vue'
import { hatch } from 'ldrs'
import { isMobile } from '../utils/screen'
import { loginWithGoogle } from '../utils/google'
hatch.register()
@@ -364,6 +365,12 @@ export default {
onMounted(async () => {
await loadOptions()
fetchContent()
if (!isLogin()) {
//
}
setTimeout(() => {
loginWithGoogle()
}, 3000)
})
watch([selectedCategory, selectedTags], () => {

View File

@@ -53,7 +53,7 @@
<script>
import { API_BASE_URL, toast } from '../main'
import { setToken, loadCurrentUser } from '../utils/auth'
import { googleSignIn } from '../utils/google'
import { loginWithGoogle } from '../utils/google'
import { githubAuthorize } from '../utils/github'
import { discordAuthorize } from '../utils/discord'
import { twitterAuthorize } from '../utils/twitter'
@@ -61,6 +61,9 @@ import BaseInput from '../components/BaseInput.vue'
export default {
name: 'LoginPageView',
components: { BaseInput },
setup() {
return { loginWithGoogle }
},
data() {
return {
username: '',
@@ -99,16 +102,7 @@ export default {
toast.error('登录失败')
}
},
loginWithGoogle() {
googleSignIn(
() => {
this.$router.push('/')
},
(token) => {
this.$router.push('/signup-reason?token=' + token)
}
)
},
loginWithGithub() {
githubAuthorize()
},
@@ -117,7 +111,7 @@ export default {
},
loginWithTwitter() {
twitterAuthorize()
}
},
}
}
</script>

View File

@@ -67,7 +67,7 @@
</div>
<div class="other-signup-page-content">
<div class="signup-page-button" @click="signupWithGoogle">
<div class="signup-page-button" @click="loginWithGoogle">
<img class="signup-page-button-icon" src="../assets/icons/google.svg" alt="Google Logo" />
<div class="signup-page-button-text">Google 注册</div>
</div>
@@ -89,7 +89,7 @@
<script>
import { API_BASE_URL, toast } from '../main'
import { googleSignIn } from '../utils/google'
import { loginWithGoogle } from '../utils/google'
import { githubAuthorize } from '../utils/github'
import { discordAuthorize } from '../utils/discord'
import { twitterAuthorize } from '../utils/twitter'
@@ -97,7 +97,9 @@ import BaseInput from '../components/BaseInput.vue'
export default {
name: 'SignupPageView',
components: { BaseInput },
setup() {
return { loginWithGoogle }
},
data() {
return {
emailStep: 0,
@@ -201,13 +203,6 @@ export default {
toast.error('注册失败')
}
},
signupWithGoogle() {
googleSignIn(() => {
this.$router.push('/')
}, (token) => {
this.$router.push('/signup-reason?token=' + token)
})
},
signupWithGithub() {
githubAuthorize()
},