First commit
This commit is contained in:
46
sso-demo/models/user.js
Normal file
46
sso-demo/models/user.js
Normal file
@@ -0,0 +1,46 @@
|
||||
// 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
|
||||
};
|
||||
Reference in New Issue
Block a user