91 lines
2.2 KiB
Vue
91 lines
2.2 KiB
Vue
<template>
|
|
<!-- Remote auth completion mode -->
|
|
<RemoteAuthComplete
|
|
v-if="remoteAuthToken"
|
|
:token="remoteAuthToken"
|
|
@back="handleBack"
|
|
@completed="handleRemoteCompleted"
|
|
/>
|
|
<!-- Normal restricted auth mode -->
|
|
<RestrictedAuth
|
|
v-else
|
|
:mode="authMode"
|
|
@authenticated="handleAuthenticated"
|
|
@back="handleBack"
|
|
/>
|
|
</template>
|
|
|
|
<script setup>
|
|
import { computed, onMounted, ref } from 'vue'
|
|
import RestrictedAuth from '@/components/RestrictedAuth.vue'
|
|
import RemoteAuthComplete from '@/components/RemoteAuthComplete.vue'
|
|
|
|
// Check if this is a remote auth URL: /{token} or /auth/{token}
|
|
// The token is a 5-word passphrase like "word1.word2.word3.word4.word5"
|
|
const remoteAuthToken = ref(null)
|
|
|
|
function extractRemoteToken() {
|
|
const path = window.location.pathname
|
|
// Match /{token} or /auth/{token} where token is a passphrase with dots
|
|
const match = path.match(/\/(?:auth\/)?([^/]+)$/)
|
|
if (match) {
|
|
const token = match[1]
|
|
// Validate it looks like a passphrase (contains dots, likely 5 words)
|
|
const parts = token.split('.')
|
|
if (parts.length === 5 && parts.every(p => p.length > 0)) {
|
|
return token
|
|
}
|
|
}
|
|
return null
|
|
}
|
|
|
|
// Detect mode from URL hash fragment
|
|
const authMode = computed(() => {
|
|
const params = new URLSearchParams(window.location.hash.slice(1))
|
|
const mode = params.get('mode')
|
|
if (mode === 'reauth') return 'reauth'
|
|
if (mode === 'forbidden') return 'forbidden'
|
|
return 'login'
|
|
})
|
|
|
|
function postToParent(message) {
|
|
if (window.parent && window.parent !== window) {
|
|
window.parent.postMessage(message, '*')
|
|
}
|
|
}
|
|
|
|
function handleAuthenticated(result) {
|
|
postToParent({
|
|
type: 'auth-success',
|
|
authenticated: true,
|
|
sessionToken: result.session_token
|
|
})
|
|
}
|
|
|
|
function handleBack() {
|
|
postToParent({
|
|
type: 'auth-back'
|
|
})
|
|
}
|
|
|
|
function handleRemoteCompleted() {
|
|
// Remote auth completed - the other device is now logged in
|
|
// This device doesn't need to do anything special
|
|
}
|
|
|
|
onMounted(() => {
|
|
// Check for remote auth token in URL
|
|
remoteAuthToken.value = extractRemoteToken()
|
|
|
|
postToParent({
|
|
type: 'auth-ready'
|
|
})
|
|
|
|
window.addEventListener('keydown', (event) => {
|
|
if (event.key === 'Escape') {
|
|
handleBack()
|
|
}
|
|
})
|
|
})
|
|
</script>
|