u
This commit is contained in:
@@ -31,6 +31,8 @@ import { auth, company, number as numberApi } from '../api';
|
||||
* @property {AuthUser|null} user Authenticated user, or `null` for anonymous sessions.
|
||||
* @property {string|null} googleClientId Google Identity Services client ID.
|
||||
* @property {number|null} schemaVersion Database schema version returned by the backend.
|
||||
* @property {boolean} vhost Whether vhost mode is enabled.
|
||||
* @property {string|null} vhostSettings Vhost configuration string (e.g. posport:41420;posip:147.135.129.77).
|
||||
* @property {'loading'|'anon'|'authed'} status Current authentication lifecycle state.
|
||||
* @property {boolean} hasAuth True when the session has a valid authenticated user.
|
||||
* @property {boolean} hasCompany True when `hasAuth` is true AND a company is selected.
|
||||
@@ -49,6 +51,8 @@ const initialState = {
|
||||
user: null,
|
||||
googleClientId: null,
|
||||
schemaVersion: null,
|
||||
vhost: false,
|
||||
vhostSettings: null,
|
||||
status: 'loading',
|
||||
hasAuth: false,
|
||||
hasCompany: false,
|
||||
@@ -124,6 +128,8 @@ function buildAuthState(user, status, extra = {}) {
|
||||
status,
|
||||
hasAuth,
|
||||
hasCompany,
|
||||
vhost: authAutomat?.state?.vhost ?? false,
|
||||
vhostSettings: authAutomat?.state?.vhostSettings ?? null,
|
||||
retryNotification: null,
|
||||
...extra,
|
||||
};
|
||||
@@ -143,22 +149,30 @@ function applySession(nextSession) {
|
||||
nextSession.schemaVersion !== undefined
|
||||
? nextSession.schemaVersion
|
||||
: (authAutomat.state.schemaVersion ?? null);
|
||||
const vhost =
|
||||
nextSession.vhost !== undefined
|
||||
? Boolean(nextSession.vhost)
|
||||
: (authAutomat.state.vhost ?? false);
|
||||
const vhostSettings =
|
||||
nextSession.vhostSettings !== undefined
|
||||
? nextSession.vhostSettings
|
||||
: (authAutomat.state.vhostSettings ?? null);
|
||||
|
||||
if (!nextSession.user) {
|
||||
if (authAutomat.state.status !== 'authed') {
|
||||
const nextState = authAutomat.setState(
|
||||
buildAuthState(null, 'anon', { googleClientId, schemaVersion, retryNotification: null })
|
||||
buildAuthState(null, 'anon', { googleClientId, schemaVersion, vhost, vhostSettings, retryNotification: null })
|
||||
);
|
||||
syncSse(nextState);
|
||||
} else {
|
||||
authAutomat.setState({ googleClientId, schemaVersion, retryNotification: null });
|
||||
authAutomat.setState({ googleClientId, schemaVersion, vhost, vhostSettings, retryNotification: null });
|
||||
}
|
||||
return nextSession;
|
||||
}
|
||||
|
||||
const user = mergeUser(authAutomat.state.user, nextSession.user);
|
||||
const nextState = authAutomat.setState(
|
||||
buildAuthState(user, 'authed', { googleClientId, schemaVersion, retryNotification: null })
|
||||
buildAuthState(user, 'authed', { googleClientId, schemaVersion, vhost, vhostSettings, retryNotification: null })
|
||||
);
|
||||
syncSse(nextState);
|
||||
emit({ type: AUTH_SESSION_ESTABLISHED });
|
||||
@@ -352,6 +366,8 @@ export const selectSelectedCompanyId = () =>
|
||||
authAutomat.state.hasCompany ? authAutomat.state.user?.selectedCompanyId ?? null : null;
|
||||
export const selectRetryNotification = () => authAutomat.state.retryNotification;
|
||||
export const selectSchemaVersion = () => authAutomat.state.schemaVersion;
|
||||
export const selectVhost = () => Boolean(authAutomat.state.vhost);
|
||||
export const selectVhostSettings = () => authAutomat.state.vhostSettings;
|
||||
|
||||
/**
|
||||
* Re-reads `GET /api/auth/me` from the server.
|
||||
|
||||
Reference in New Issue
Block a user