Accounts get a profile page with an uploaded picture, shown in the sidebar, the room bar, and every human message. Pictures live in the SQLite database and are served through an authenticated route. Hardening from the security audit: preview hosts expire after 24 hours and carry no-referrer; removing a member or archiving a room ends their event feed, presence socket, and terminal within seconds; previews and the terminal pin the SSH host key; invites are claimed atomically; missing accounts spend the same argon2 time as wrong passwords; registration is closed by default; WebSockets check the origin; and the master key is created with mode 0600. The Dockerfile builds one image with the static client and the server. The Helm chart runs a single replica with a SQLite volume, a wildcard preview ingress, and the proxy settings the event feed and uploads need. It refuses more than one replica because state is in process.
72 lines
1.6 KiB
TypeScript
72 lines
1.6 KiB
TypeScript
import type { BootstrapResponse, User } from '~/types'
|
|
|
|
interface SessionState {
|
|
loaded: boolean
|
|
needsSetup: boolean
|
|
user: User | null
|
|
allowRegistration: boolean
|
|
publicUrl: string
|
|
previewOrigin: string
|
|
}
|
|
|
|
let inflight: Promise<SessionState> | null = null
|
|
|
|
export function useSession() {
|
|
const state = useState<SessionState>('session', () => ({
|
|
loaded: false,
|
|
needsSetup: false,
|
|
user: null,
|
|
allowRegistration: false,
|
|
publicUrl: '',
|
|
previewOrigin: '',
|
|
}))
|
|
const api = useApi()
|
|
|
|
function apply(boot: BootstrapResponse) {
|
|
state.value = {
|
|
loaded: true,
|
|
needsSetup: boot.needs_setup,
|
|
user: boot.user,
|
|
allowRegistration: boot.allow_registration,
|
|
publicUrl: boot.public_url,
|
|
previewOrigin: boot.preview_origin,
|
|
}
|
|
return state.value
|
|
}
|
|
|
|
async function load(force = false): Promise<SessionState> {
|
|
if (state.value.loaded && !force) return state.value
|
|
if (!inflight) {
|
|
inflight = api
|
|
.get<BootstrapResponse>('/bootstrap')
|
|
.then((boot) => apply(boot))
|
|
.finally(() => {
|
|
inflight = null
|
|
})
|
|
}
|
|
return inflight
|
|
}
|
|
|
|
function setUser(next: User | null) {
|
|
state.value = { ...state.value, user: next }
|
|
}
|
|
|
|
async function signOut() {
|
|
try {
|
|
await api.post('/logout')
|
|
} catch {
|
|
// The cookie is cleared server-side when the session is still valid.
|
|
}
|
|
state.value = { ...state.value, user: null }
|
|
await navigateTo('/login')
|
|
}
|
|
|
|
return {
|
|
session: state,
|
|
user: computed(() => state.value.user),
|
|
load,
|
|
setUser,
|
|
signOut,
|
|
}
|
|
}
|