mirror of
https://github.com/OpenSquawk/OpenSquawk
synced 2026-08-11 12:05:33 +08:00
Support prefilled register mode from query params
This commit is contained in:
@@ -285,6 +285,7 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import {reactive, ref, computed, watch, onMounted} from 'vue'
|
import {reactive, ref, computed, watch, onMounted} from 'vue'
|
||||||
import {useRoute, useRouter} from 'vue-router'
|
import {useRoute, useRouter} from 'vue-router'
|
||||||
|
import type {LocationQueryValue} from 'vue-router'
|
||||||
import {useHead} from '#imports'
|
import {useHead} from '#imports'
|
||||||
import {useAuthStore} from '~/stores/auth'
|
import {useAuthStore} from '~/stores/auth'
|
||||||
import {useApi} from '~/composables/useApi'
|
import {useApi} from '~/composables/useApi'
|
||||||
@@ -338,6 +339,34 @@ const registerLoading = ref(false)
|
|||||||
const registerError = ref('')
|
const registerError = ref('')
|
||||||
const invitationStatus = ref<'unknown' | 'checking' | 'valid' | 'invalid'>('unknown')
|
const invitationStatus = ref<'unknown' | 'checking' | 'valid' | 'invalid'>('unknown')
|
||||||
|
|
||||||
|
function getQueryParam(query: LocationQueryValue | LocationQueryValue[] | undefined) {
|
||||||
|
if (Array.isArray(query)) return query[0] ?? ''
|
||||||
|
return query ?? ''
|
||||||
|
}
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => route.query,
|
||||||
|
() => {
|
||||||
|
const queryMode = getQueryParam(route.query.mode)
|
||||||
|
if (queryMode === 'register' || queryMode === 'login') {
|
||||||
|
mode.value = queryMode as Mode
|
||||||
|
}
|
||||||
|
|
||||||
|
const emailParam = getQueryParam(route.query.email)
|
||||||
|
if (emailParam) {
|
||||||
|
registerForm.email = emailParam
|
||||||
|
loginForm.email = emailParam
|
||||||
|
}
|
||||||
|
|
||||||
|
const inviteParam =
|
||||||
|
getQueryParam(route.query.invite || route.query.invitationCode || route.query.code)
|
||||||
|
if (inviteParam) {
|
||||||
|
registerForm.invitationCode = inviteParam
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{immediate: true}
|
||||||
|
)
|
||||||
|
|
||||||
const canRegister = computed(() =>
|
const canRegister = computed(() =>
|
||||||
Boolean(
|
Boolean(
|
||||||
registerForm.email &&
|
registerForm.email &&
|
||||||
|
|||||||
Reference in New Issue
Block a user