mirror of
https://github.com/Permissionless-Software-Foundation/x402-base-facilitator.git
synced 2026-09-21 16:52:01 -07:00
Remove the salt field from the user model, as it's redundant
This commit is contained in:
+1
-1
@@ -8,7 +8,7 @@ passport.serializeUser((user, done) => {
|
||||
|
||||
passport.deserializeUser(async (id, done) => {
|
||||
try {
|
||||
const user = await User.findById(id, '-password -salt')
|
||||
const user = await User.findById(id, '-password')
|
||||
done(null, user)
|
||||
} catch(err) {
|
||||
done(err)
|
||||
|
||||
@@ -16,7 +16,7 @@ export async function ensureUser(ctx, next) {
|
||||
ctx.throw(401)
|
||||
}
|
||||
|
||||
const user = await User.findById(decoded.id, '-password -salt')
|
||||
const user = await User.findById(decoded.id, '-password')
|
||||
if (!user) {
|
||||
ctx.throw(401)
|
||||
}
|
||||
|
||||
+1
-3
@@ -7,8 +7,7 @@ const User = new mongoose.Schema({
|
||||
type: { type: String, default: 'User' },
|
||||
name: { type: String },
|
||||
username: { type: String, required: true, unique: true },
|
||||
password: { type: String, required: true },
|
||||
salt: { type: String }
|
||||
password: { type: String, required: true }
|
||||
})
|
||||
|
||||
User.pre('save', function preSave(next) {
|
||||
@@ -29,7 +28,6 @@ User.pre('save', function preSave(next) {
|
||||
if (err) { throw new Error(err) }
|
||||
|
||||
user.password = hash
|
||||
user.salt = salt
|
||||
|
||||
next(null)
|
||||
})
|
||||
|
||||
@@ -64,7 +64,6 @@ export async function authUser(ctx, next) {
|
||||
const response = user.toJSON()
|
||||
|
||||
delete response.password
|
||||
delete response.salt
|
||||
|
||||
ctx.body = {
|
||||
token,
|
||||
|
||||
@@ -50,8 +50,7 @@ export async function createUser(ctx) {
|
||||
const response = user.toJSON()
|
||||
|
||||
delete response.password
|
||||
delete response.salt
|
||||
|
||||
|
||||
ctx.body = {
|
||||
user: response,
|
||||
token
|
||||
@@ -86,7 +85,7 @@ export async function createUser(ctx) {
|
||||
* @apiUse TokenError
|
||||
*/
|
||||
export async function getUsers(ctx) {
|
||||
const users = await User.find({}, '-password -salt')
|
||||
const users = await User.find({}, '-password')
|
||||
ctx.body = { users }
|
||||
}
|
||||
|
||||
@@ -119,7 +118,7 @@ export async function getUsers(ctx) {
|
||||
*/
|
||||
export async function getUser(ctx, next) {
|
||||
try {
|
||||
const user = await User.findById(ctx.params.id, '-password -salt')
|
||||
const user = await User.findById(ctx.params.id, '-password')
|
||||
if (!user) {
|
||||
ctx.throw(404)
|
||||
}
|
||||
|
||||
@@ -39,7 +39,6 @@ describe('Auth', () => {
|
||||
res.body.user.should.have.property('username')
|
||||
res.body.user.username.should.equal('test')
|
||||
expect(res.body.user.password).to.not.exist
|
||||
expect(res.body.user.salt).to.not.exist
|
||||
|
||||
context.user = res.body.user
|
||||
context.token = res.body.token
|
||||
|
||||
@@ -33,7 +33,6 @@ describe('Users', () => {
|
||||
res.body.user.should.have.property('username')
|
||||
res.body.user.username.should.equal('supercoolname')
|
||||
expect(res.body.user.password).to.not.exist
|
||||
expect(res.body.user.salt).to.not.exist
|
||||
|
||||
context.user = res.body.user
|
||||
context.token = res.body.token
|
||||
@@ -99,7 +98,6 @@ describe('Users', () => {
|
||||
res.body.should.have.property('user')
|
||||
|
||||
expect(res.body.user.password).to.not.exist
|
||||
expect(res.body.user.salt).to.not.exist
|
||||
|
||||
done()
|
||||
})
|
||||
@@ -138,7 +136,6 @@ describe('Users', () => {
|
||||
res.body.user.should.have.property('username')
|
||||
res.body.user.username.should.equal('updatedcoolname')
|
||||
expect(res.body.user.password).to.not.exist
|
||||
expect(res.body.user.salt).to.not.exist
|
||||
|
||||
done()
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user