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