import {friendlyError,deliveryLabel,eventLabel} from './userLanguage.mjs'; import React,{useEffect,useState} from 'react'; import {authStatus,decideAccess,enrollTotp,registerAccount,submitAccessRequest,verifyTotp} from './authSecurity.mjs'; // Uses existing dashboard classes; no new theme/layout system or auth vendor. export default function AccountSecurity({client,user,onChange}){ const [status,setStatus]=useState(null),[factors,setFactors]=useState([]),[unfinished,setUnfinished]=useState([]),[enrollment,setEnrollment]=useState(null); const [code,setCode]=useState(''),[factorId,setFactorId]=useState(''),[name,setName]=useState(''); const [email,setEmail]=useState(''),[password,setPassword]=useState(''),[notice,setNotice]=useState(''),[busy,setBusy]=useState(false); const [directory,setDirectory]=useState([]),[delivery,setDelivery]=useState([]); const registrationEnabled=window.DEFECTRAG_PUBLIC_CONFIG?.registrationEnabled===true; async function refresh(){ if(!user){setStatus(null);setDirectory([]);setDelivery([]);return} const posture=await authStatus(client);setStatus(posture); const {data,error}=await client.auth.mfa.listFactors();if(error)throw error; const verified=(data.totp||[]).filter(f=>f.status==='verified');setFactors(verified); setUnfinished((data.all||[]).filter(f=>f.factor_type==='totp'&&f.status==='unverified')); setFactorId(previous=>verified.some(f=>f.id===previous)?previous:verified[0]?.id||''); if(posture.role==='developer'&&posture.approved&&posture.aal2){ const [members,messages]=await Promise.all([client.rpc('defectrag_access_directory'),client.rpc('defectrag_notification_status')]); if(members.error)throw members.error;if(messages.error)throw messages.error; setDirectory(members.data||[]);setDelivery(messages.data||[]); }else{setDirectory([]);setDelivery([])} } async function run(action){setBusy(true);setNotice('');try{await action()}catch(error){setNotice(error.message||'Security request failed.')}finally{setBusy(false)}} useEffect(()=>{let active=true; setEnrollment(null);setCode('');setDirectory([]);setDelivery([]); if(client&&user)refresh().catch(error=>{if(active)setNotice(error.message)}); else setStatus(null); return()=>{active=false}; },[client,user?.id]); async function verified(){ await verifyTotp(client,enrollment?.id||factorId,code);setCode('');setEnrollment(null); await refresh();onChange();setNotice('Security code verified. Staff access is available only after the account is approved.'); } return
{user&&

Sign-in and account security

} {notice&&

{friendlyError(notice)}

} {!user?registrationEnabled?
New to Staff work? Create an account
{event.preventDefault();run(async()=>{ await registerAccount(client,{email,password,displayName:name,redirectTo:location.origin+location.pathname}); setPassword('');setNotice('Check the inbox and Spam folder for a confirmation email. Open its link, sign in, then choose Request staff access. A Developer must approve the request before Staff work is available.'); })}}>

New to Staff work? Create an account, confirm the email, then request access. The public demo can be used without an account.

:

New account registration is currently closed. Existing Staff can sign in below. The public demo is still available.

:<>

Access: {status?.revoked?'revoked':status?.approved?'approved':status?.request_status||'not requested'} ยท Authenticator: {status?.aal2?'security code verified':'enter security code'}

{status&&!status.approved&&!status.revoked&&!status.request_status&&
{event.preventDefault();run(async()=>{await submitAccessRequest(client,name);await refresh();setNotice('Request sent. Check back here for Developer approval. Team and private Staff work are not available while the request is waiting.');onChange()})}}>
}

Use an authenticator app for the extra six-digit sign-in code. Keep access to that app. If it is lost, contact the workspace administrator; resetting the password does not remove this security check.

{!enrollment&&!factors.length&&!unfinished.length&&} {!enrollment&&unfinished.map(f=>

Authenticator setup was not finished.

)} {enrollment&&

Open an authenticator app, scan this private QR code, then enter the six-digit code below to finish. Do not share the QR code or security codes.

Private authenticator enrollment QR code
} {!enrollment&&factors.length>0&&status?.aal2&&

The security code is verified for this sign-in.

} {(enrollment||(factors.length>0&&!status?.aal2))&&
{event.preventDefault();run(verified)}}> {!enrollment&&}
} {status?.role==='developer'&&status.approved&&status.aal2&&<>

Staff access management

Approve or reject requests that are still waiting. Removing access stops new Staff actions but keeps inspection history.

{directory.map(row=>)}
AccountStatusRoleAction
{row.display_name}
{row.email}
{row.status}{row.role||'applicant'}{row.user_id!==user.id&&(row.status==='pending'?['approve','reject']:row.status==='approved'?['revoke']:[]).map(action=>)}

Email delivery

Waiting emails have not been sent. Delivery depends on administrator settings and the email service being available. Sent means the email service accepted the message; it may still reach Spam or fail to arrive.

{delivery.map(row=>)}
EventDeliveryAttempts
{eventLabel(row.kind)}{deliveryLabel(row.status)}{row.attempts}{row.status==='dead'&&}
} }
; }