overleaf/overleaf · error · Error
user ID not valid
Error message
user ID not valid
What it means
_validateUserIdList in clear_sessions_set_must_reconfirm.mjs iterates a list of user IDs and throws 'user ID not valid' for the first entry that is not a syntactically valid MongoDB ObjectId (per ObjectId.isValid). The script requires every line of the input file to be a 24-character hex string so it can pass real IDs to UserUpdater. It is an input-validation guard, not a database lookup: a well-formed-but-unknown ID would pass this check and fail later in _handleUser.
Source
Thrown at services/web/scripts/clear_sessions_set_must_reconfirm.mjs:30
failedSet: [],
success: [],
printSummary: () => {
console.log(
{
success: processLogger.success,
failedClear: processLogger.failedClear,
failedSet: processLogger.failedSet,
},
`\nDONE. ${processLogger.success.length} successful. ${processLogger.failedClear.length} failed to clear sessions. ${processLogger.failedSet.length} failed to set must_reconfirm.`
)
},
}
function _validateUserIdList(userIds) {
if (!Array.isArray(userIds)) throw new Error('users is not an array')
userIds.forEach(userId => {
if (!ObjectId.isValid(userId)) throw new Error('user ID not valid')
})
}
async function _handleUser(userId) {
try {
await UserUpdater.promises.updateUser(userId, {
$set: { must_reconfirm: true },
})
} catch (error) {
console.log(`Failed to set must_reconfirm ${userId}`, error)
processLogger.failedSet.push(userId)
return
}
try {
await UserAuditLogHandler.promises.addEntry(
userId,
'must-reset-password-set',View on GitHub (pinned to 28ad3b03b7)
Solutions
- Open the users file and fix or remove the line that is not a 24-char hex ObjectId string (the error stops at the first bad ID).
- Validate the file before running: grep -nEv '^[0-9a-fA-F]{24}$' users.txt to list bad lines.
- Filter in code: users.map(s=>s.trim()).filter(s=>ObjectId.isValid(s)) before calling the script's helpers.
- If IDs come from an upstream query, re-export using the correct projection (e.g. _id) so raw ObjectIds are written.
Example fix
// before (users.txt) user_id 65d1f1e0c9e77d001a2b3c4 // after (users.txt) 65d1f1e0c9e77d001a2b3c4
Defensive patterns
Strategy: validation
Validate before calling
import { ObjectId } from 'mongodb'
const ids = fs.readFileSync(file, 'utf8').trim().split('\n').map(s => s.trim()).filter(Boolean)
const bad = ids.filter(id => !ObjectId.isValid(id))
if (bad.length) throw new Error(`invalid ObjectIds at lines: ${bad.join(', ')}`) Type guard
const isValidObjectId = (v) => typeof v === 'string' && /^[0-9a-fA-F]{24}$/.test(v) Try / catch
try {
await script.run(userIds)
} catch (err) {
if (err.message === 'user ID not valid') {
console.error('Bad ID in input file; sanitize with ObjectId.isValid filter')
} else throw err
} Prevention
- Pre-sanitize input files with grep -nEv '^[0-9a-fA-F]{24}$' to find bad lines
- Strip blank lines and whitespace before validating
- Never mix emails and ObjectIds in one ID list
- Validate the whole list, not just the first element, before invoking the script
When it happens
Trigger: Running `node clear_sessions_set_must_reconfirm.mjs users.txt` where the file contains a line that is not a valid ObjectId: an email instead of an ID, a truncated ID, whitespace-only or blank lines that survive trimming, or IDs copied with extra characters/quotes.
Common situations: Exporting user lists from logs or CSVs where a header row ('user_id') or non-user rows get mixed in; hand-edited ID files; older exports using a different ID format; forgetting the file is newline-separated ObjectIds.
Related errors
- user ID not valid: ${userId}
- provide a valid object id as --project-id, --doc-id and --us
- invalid project id
- Document not found
- user ID ${userId} is not valid
AI-assisted analysis of overleaf/overleaf@28ad3b03b7 (2026-09-03).
Data as JSON: /api/errors/8ca7f639a7f81dc5.
Report an issue: GitHub.