fix: pull missing fields
This commit is contained in:
1 parent
f0c371f987
commit
b82b43b4c6
2 files changed
+28
-19
No files matched your search
@@ -24,7 +24,9 @@ import jwt from "jsonwebtoken"
|
|||||||
*/
|
*/
|
||||||
export default async (req, res) => {
|
export default async (req, res) => {
|
||||||
const schema = Validator.object().keys({
|
const schema = Validator.object().keys({
|
||||||
email: Validator.string().email().required(),
|
email: Validator.string()
|
||||||
|
.email()
|
||||||
|
.required(),
|
||||||
token: Validator.string().required(),
|
token: Validator.string().required(),
|
||||||
password: Validator.string().required(),
|
password: Validator.string().required(),
|
||||||
})
|
})
|
||||||
@@ -34,23 +36,21 @@ export default async (req, res) => {
|
|||||||
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
const customerService = req.scope.resolve("customerService")
|
||||||
const customerService = req.scope.resolve("customerService")
|
let customer = await customerService.retrieveByEmail(value.email, {
|
||||||
let customer = await customerService.retrieveByEmail(value.email)
|
select: ["id", "password_hash"],
|
||||||
|
})
|
||||||
|
|
||||||
const decodedToken = await jwt.verify(value.token, customer.password_hash)
|
const decodedToken = jwt.verify(value.token, customer.password_hash)
|
||||||
if (!decodedToken || customer.id !== decodedToken.customer_id) {
|
if (!decodedToken || customer.id !== decodedToken.customer_id) {
|
||||||
res.status(401).send("Invalid or expired password reset token")
|
res.status(401).send("Invalid or expired password reset token")
|
||||||
return
|
return
|
||||||
}
|
|
||||||
|
|
||||||
await customerService.update(customer.id, {
|
|
||||||
password: value.password,
|
|
||||||
})
|
|
||||||
|
|
||||||
customer = await customerService.retrieve(customer.id)
|
|
||||||
res.status(200).json({ customer })
|
|
||||||
} catch (error) {
|
|
||||||
throw error
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await customerService.update(customer.id, {
|
||||||
|
password: value.password,
|
||||||
|
})
|
||||||
|
|
||||||
|
customer = await customerService.retrieve(customer.id)
|
||||||
|
res.status(200).json({ customer })
|
||||||
}
|
}
|
||||||
@@ -94,7 +94,16 @@ class CustomerService extends BaseService {
|
|||||||
* @return {string} the generated JSON web token
|
* @return {string} the generated JSON web token
|
||||||
*/
|
*/
|
||||||
async generateResetPasswordToken(customerId) {
|
async generateResetPasswordToken(customerId) {
|
||||||
const customer = await this.retrieve(customerId)
|
const customer = await this.retrieve(customerId, {
|
||||||
|
select: [
|
||||||
|
"id",
|
||||||
|
"has_account",
|
||||||
|
"password_hash",
|
||||||
|
"email",
|
||||||
|
"first_name",
|
||||||
|
"last_name",
|
||||||
|
],
|
||||||
|
})
|
||||||
|
|
||||||
if (!customer.has_account) {
|
if (!customer.has_account) {
|
||||||
throw new MedusaError(
|
throw new MedusaError(
|
||||||
|
|||||||
Reference in new issue
Block a user