fix(auth): remove sandbox default session fallback

This commit is contained in:
Haitao Pan 2026-04-09 09:20:24 +08:00
parent 6dfc9454fa
commit 9cf1c167e8
4 changed files with 7 additions and 16 deletions

View File

@ -141,10 +141,7 @@ export async function GET(request: NextRequest) {
Boolean(rawUser.readOnly) ||
normalizedGroups.some((group) => group.toLowerCase() === "readonly role") ||
rawRole === "readonly" ||
rawRole === "read_only" ||
String(rawUser.email ?? "")
.trim()
.toLowerCase() === "sandbox@svc.plus";
rawRole === "read_only";
const normalizedProxyUuid =
typeof rawUser.proxyUuid === "string" && rawUser.proxyUuid.trim().length > 0
? rawUser.proxyUuid.trim()

View File

@ -65,6 +65,8 @@ const KNOWN_ROLE_MAP: Record<string, UserRole> = {
member: 'user',
}
const GUEST_SANDBOX_TENANT_ID = 'guest-sandbox'
const GUEST_SANDBOX_TENANT_NAME = 'Guest Sandbox'
function normalizeRole(input?: string | null): UserRole {
if (!input || typeof input !== 'string') {
return 'guest'
@ -162,11 +164,9 @@ async function fetchSessionUser(): Promise<User | null> {
.filter((value): value is string => typeof value === 'string' && value.trim().length > 0)
.map((value) => value.trim())
: []
const normalizedEmail = typeof email === 'string' ? email.trim().toLowerCase() : ''
const inferredReadOnly =
rawRole === 'readonly' ||
rawRole === 'read_only' ||
normalizedEmail === 'sandbox@svc.plus' ||
normalizedGroups.some((value) => value.toLowerCase() === 'readonly role')
const normalizedReadOnly = Boolean(sessionUser.readOnly) || inferredReadOnly
const normalizedProxyUuid =

View File

@ -57,10 +57,7 @@ export default function UserOverview({ hideMfaMainPrompt = false }: UserOverview
const username = user?.username ?? '—'
const email = user?.email ?? '—'
const docsUrl = mfaCopy.actions.docsUrl
const normalizedEmail = user?.email?.toLowerCase() ?? ''
const isGuestSandboxReadOnly = Boolean(
user?.isReadOnly && (normalizedEmail === 'sandbox@svc.plus'),
)
const isGuestSandboxReadOnly = Boolean(user?.isGuest && user?.isReadOnly)
const guestUuidExpiresAtText = useMemo(() => {
if (!isGuestSandboxReadOnly || !user?.proxyUuidExpiresAt) {
return null

View File

@ -42,10 +42,7 @@ export default function UserCenterAgentRoute() {
const user = useUserStore((state) => state.user)
const { data: nodes, error, isLoading, mutate } = useSWR<VlessNode[]>('user-center-agent-nodes', fetchAgentNodes)
const [boundNode, setBoundNode] = useState<VlessNode | null>(null)
const normalizedEmail = user?.email?.toLowerCase() ?? ''
const isGuestSandboxReadOnly = Boolean(
user?.isReadOnly && (normalizedEmail === 'sandbox@svc.plus'),
)
const isGuestSandboxReadOnly = Boolean(user?.isGuest && user?.isReadOnly)
const visibleNodes = useMemo(() => {
return (nodes ?? []).filter((node) => {
if (isGuestSandboxReadOnly) {
@ -95,7 +92,7 @@ export default function UserCenterAgentRoute() {
// Guest sandbox behavior: if root has bound a preferred node, ensure it is first,
// but still show all regions/nodes to keep the demo experience useful.
if (isGuestSandboxReadOnly && normalizedEmail && boundAddress) {
if (isGuestSandboxReadOnly && boundAddress) {
const matched = nodes?.find((n) => n.address === boundAddress)
const preferred = matched ?? boundNode ?? null
if (preferred) {
@ -110,7 +107,7 @@ export default function UserCenterAgentRoute() {
}
return base
}, [isGuestSandboxReadOnly, nodes, visibleNodes, normalizedEmail, boundAddress, boundNode])
}, [isGuestSandboxReadOnly, nodes, visibleNodes, boundAddress, boundNode])
const groupedNodes = useMemo(() => {
const groups: Record<string, VlessNode[]> = {