File encryption

 Shared login status across sites
This commit is contained in:
2025-07-26 01:37:23 +08:00
parent 081f3f609e
commit 0486c0d0e5
23 changed files with 670 additions and 65 deletions

View File

@@ -1,3 +1,27 @@
import { defineStore } from 'pinia'
import { ref } from 'vue'
export const useServicesStore = defineStore('services', () => {})
export const useServicesStore = defineStore('services', () => {
const services = ref<Record<string, string>>({})
async function fetchServices() {
try {
const response = await fetch('/cgi/.well-known/services')
if (!response.ok) {
throw new Error('Network response was not ok')
}
const data = await response.json()
services.value = data
} catch (error) {
console.error('Failed to fetch services:', error)
services.value = {}
}
}
function getSerivceUrl(serviceName: string, ...parts: string[]): string | null {
let baseUrl = services.value[serviceName] || null
return baseUrl ? `${baseUrl}/${parts.join('/')}` : null
}
return { services, fetchServices, getSerivceUrl }
})

View File

@@ -43,8 +43,24 @@ export const useUserStore = defineStore('user', () => {
// router.push('/login')
}
async function initialize() {
await fetchUser()
function initialize() {
const allowedOrigin = import.meta.env.DEV ? window.location.origin : 'https://id.solian.app'
window.addEventListener('message', (event) => {
// IMPORTANT: Always check the origin of the message for security!
// This prevents malicious scripts from sending fake login status updates.
// Ensure event.origin exactly matches your identity service's origin.
if (event.origin !== allowedOrigin) {
console.warn(`[SYNC] Message received from unexpected origin: ${event.origin}. Ignoring.`)
return // Ignore messages from unknown origins
}
// Check if the message is the type we're expecting
if (event.data && event.data.type === 'DY:LOGIN_STATUS_CHANGE') {
const { loggedIn } = event.data
console.log(`[SYNC] Received login status change: ${loggedIn}`)
fetchUser() // Re-fetch user data on login status change
}
})
}
return {