Skip to content

useMongocampSelf ​

Who "I" am, for UI decisions such as protecting one's own row — in both auth modes.

ts
const { userId, status, load } = useMongocampSelf()
await load()
const isSelf = (user: string) => userId.value !== '' && user === userId.value
ReturnDescription
userIdComputedRef<string> — session mode: the signed-in user ('' after a logout); server proxy mode: the user that owns the server's api key. '' while unknown
rolesComputedRef<string[]> — the role names of that user (session: the stored profile; proxy: the profile answer)
status'idle' | 'loading' | 'ready' | 'failed' — always 'ready' in session mode
load()Proxy mode: GET /auth/profile through the proxy, once per app (the key does not change while the app runs); callers asking together share one request. Session mode: no request. Never throws; 15 s timeout

Used by MongocampUsers (in proxy mode the api key's own row cannot be deleted, edited or given a new api key) and MongocampRoles (the key user's roles cannot be deleted, an admin one stays admin) — each would cut off the proxy.

Released under the MIT License.