Files
2026-01-15 14:12:41 +09:00

47 lines
1.2 KiB
JavaScript

// In-memory user store for demonstration purposes
// In a real application, this would be a database model (e.g., Sequelize, Mongoose)
const users = [];
let nextId = 1;
/**
* Finds a user by their SSO subject ID.
* @param {string} ssoSub - The SSO subject ID.
* @returns {Promise<object|null>} The user object or null if not found.
*/
async function findBySsoSub(ssoSub) {
return users.find(user => user.sso_sub === ssoSub) || null;
}
/**
* Finds a user by their internal ID.
* @param {number} id - The user's internal ID.
* @returns {Promise<object|null>} The user object or null if not found.
*/
async function findById(id) {
return users.find(user => user.id === id) || null;
}
/**
* Creates a new user.
* @param {object} userData - The user data.
* @param {string} userData.sso_sub - The SSO subject ID.
* @returns {Promise<object>} The newly created user object.
*/
async function createUser({ sso_sub }) {
const newUser = {
id: nextId++,
sso_sub: sso_sub,
// In a real app, you might get a username/email from the JWT or prompt the user
username: `user_${sso_sub.substring(0, 5)}`
};
users.push(newUser);
return newUser;
}
module.exports = {
findBySsoSub,
findById,
createUser
};