feat: pass invite token through signup flow

This commit is contained in:
Tim
2025-08-17 12:11:13 +08:00
parent 2dd56e27af
commit e0df78deee
18 changed files with 63 additions and 29 deletions

View File

@@ -9,11 +9,12 @@ import { discordExchange } from '~/utils/discord'
onMounted(async () => {
const url = new URL(window.location.href)
const code = url.searchParams.get('code')
const state = url.searchParams.get('state')
const result = await discordExchange(code, state, '')
const inviteToken = url.searchParams.get('state')
const result = await discordExchange(code, inviteToken, '')
if (result.needReason) {
navigateTo(`/signup-reason?token=${result.token}`, { replace: true })
const q = inviteToken ? `&invite_token=${inviteToken}` : ''
navigateTo(`/signup-reason?token=${result.token}${q}`, { replace: true })
} else {
navigateTo('/', { replace: true })
}

View File

@@ -9,11 +9,12 @@ import { githubExchange } from '~/utils/github'
onMounted(async () => {
const url = new URL(window.location.href)
const code = url.searchParams.get('code')
const state = url.searchParams.get('state')
const result = await githubExchange(code, state, '')
const inviteToken = url.searchParams.get('state')
const result = await githubExchange(code, inviteToken, '')
if (result.needReason) {
navigateTo(`/signup-reason?token=${result.token}`, { replace: true })
const q = inviteToken ? `&invite_token=${inviteToken}` : ''
navigateTo(`/signup-reason?token=${result.token}${q}`, { replace: true })
} else {
navigateTo('/', { replace: true })
}

View File

@@ -9,14 +9,17 @@ import { googleAuthWithToken } from '~/utils/google'
onMounted(async () => {
const hash = new URLSearchParams(window.location.hash.substring(1))
const idToken = hash.get('id_token')
const inviteToken = hash.get('state')
if (idToken) {
await googleAuthWithToken(
idToken,
inviteToken,
() => {
navigateTo('/', { replace: true })
},
(token) => {
navigateTo(`/signup-reason?token=${token}`, { replace: true })
const q = inviteToken ? `&invite_token=${inviteToken}` : ''
navigateTo(`/signup-reason?token=${token}${q}`, { replace: true })
},
)
} else {

View File

@@ -35,7 +35,7 @@
</div>
<div class="other-login-page-content">
<div class="login-page-button" @click="googleAuthorize">
<div class="login-page-button" @click="loginWithGoogle">
<img class="login-page-button-icon" src="../assets/icons/google.svg" alt="Google Logo" />
<div class="login-page-button-text">Google 登录</div>
</div>
@@ -115,6 +115,9 @@ const loginWithDiscord = () => {
const loginWithTwitter = () => {
twitterAuthorize()
}
const loginWithGoogle = () => {
googleAuthorize()
}
</script>
<style scoped>

View File

@@ -23,14 +23,17 @@ import BaseInput from '~/components/BaseInput.vue'
import { toast } from '~/main'
const config = useRuntimeConfig()
const API_BASE_URL = config.public.apiBaseUrl
const route = useRoute()
const reason = ref('')
const error = ref('')
const isWaitingForRegister = ref(false)
const token = ref('')
const inviteToken = ref('')
onMounted(async () => {
token.value = route.query.token || ''
inviteToken.value = route.query.invite_token || ''
if (!token.value) {
await navigateTo({ path: '/signup' }, { replace: true })
}
@@ -50,8 +53,9 @@ const submit = async () => {
'Content-Type': 'application/json',
},
body: JSON.stringify({
token: this.token,
reason: this.reason,
token: token.value,
reason: reason.value,
...(inviteToken.value ? { inviteToken: inviteToken.value } : {}),
}),
})
isWaitingForRegister.value = false

View File

@@ -69,7 +69,7 @@
</div>
<div class="other-signup-page-content">
<div class="signup-page-button" @click="googleAuthorize">
<div class="signup-page-button" @click="signupWithGoogle">
<img class="signup-page-button-icon" src="~/assets/icons/google.svg" alt="Google Logo" />
<div class="signup-page-button-text">Google 注册</div>
</div>
@@ -97,6 +97,7 @@ import { githubAuthorize } from '~/utils/github'
import { googleAuthorize } from '~/utils/google'
import { twitterAuthorize } from '~/utils/twitter'
const config = useRuntimeConfig()
const route = useRoute()
const API_BASE_URL = config.public.apiBaseUrl
const emailStep = ref(0)
const email = ref('')
@@ -109,9 +110,11 @@ const passwordError = ref('')
const code = ref('')
const isWaitingForEmailSent = ref(false)
const isWaitingForEmailVerified = ref(false)
const inviteToken = ref('')
onMounted(async () => {
username.value = route.query.u || ''
inviteToken.value = route.query.invite_token || ''
try {
const res = await fetch(`${API_BASE_URL}/api/config`)
if (res.ok) {
@@ -156,6 +159,7 @@ const sendVerification = async () => {
username: username.value,
email: email.value,
password: password.value,
...(inviteToken.value ? { inviteToken: inviteToken.value } : {}),
}),
})
isWaitingForEmailSent.value = false
@@ -184,12 +188,14 @@ const verifyCode = async () => {
body: JSON.stringify({
code: code.value,
username: username.value,
...(inviteToken.value ? { inviteToken: inviteToken.value } : {}),
}),
})
const data = await res.json()
if (res.ok) {
if (registerMode.value === 'WHITELIST') {
navigateTo(`/signup-reason?token=${data.token}`, { replace: true })
const q = inviteToken.value ? `&invite_token=${inviteToken.value}` : ''
navigateTo(`/signup-reason?token=${data.token}${q}`, { replace: true })
} else {
toast.success('注册成功,请登录')
navigateTo('/login', { replace: true })
@@ -203,14 +209,17 @@ const verifyCode = async () => {
isWaitingForEmailVerified.value = false
}
}
const signupWithGoogle = () => {
googleAuthorize(inviteToken.value)
}
const signupWithGithub = () => {
githubAuthorize()
githubAuthorize(inviteToken.value)
}
const signupWithDiscord = () => {
discordAuthorize()
discordAuthorize(inviteToken.value)
}
const signupWithTwitter = () => {
twitterAuthorize()
twitterAuthorize(inviteToken.value)
}
</script>

View File

@@ -9,11 +9,12 @@ import { twitterExchange } from '~/utils/twitter'
onMounted(async () => {
const url = new URL(window.location.href)
const code = url.searchParams.get('code')
const state = url.searchParams.get('state')
const result = await twitterExchange(code, state, '')
const inviteToken = url.searchParams.get('state')
const result = await twitterExchange(code, inviteToken, '')
if (result.needReason) {
navigateTo(`/signup-reason?token=${result.token}`, { replace: true })
const q = inviteToken ? `&invite_token=${inviteToken}` : ''
navigateTo(`/signup-reason?token=${result.token}${q}`, { replace: true })
} else {
navigateTo('/', { replace: true })
}