Reset Password token check

It’s been a while since you asked the question, but I’m answering to leave it here for possible community inquiries.

1 - I create a custom route called ‘user-x’;

2) Editing thecontroller

export default factories.createCoreController(
  "api::user-x.user-x",
  ({ strapi }) => ({
    // others codes ...
    /**
     * Check if password change token/code exists.
     * @param ctx
     * @return { Object }
     */
    async checkIfTokenExists(ctx) {
      try {
        const { code } = ctx.request.params;
        const entries = await strapi.entityService.findMany(
          "plugin::users-permissions.user",
          {
            filters: {
              resetPasswordToken: {
                $eqi: code,
              },
            },
          }
        );
        const counter = entries.length > 0;
        return ctx.send(
          {
            link_valid: counter,
            resetPasswordToken: counter ? entries?.[0]?.resetPasswordToken : "",
            message: counter ? "" : "Invalid Link",
          },
          counter ? 200 : 404
        );
      } catch (e) {
        return ctx.send(
          {
            link_valid: false,
            resetPasswordToken: "error_token_code",
            messsage: e?.message,
          },
          400
        );
      }
    },
});

3) Criando as rotas personalizadas:

export default {
  routes: [
    // Others routes
    {
      method: "GET",
      path: "/auth/reset-password/:code",
      handler: "user-x.checkIfTokenExists",
      config: {
        auth: false,
      },
    },
  ],
};

4) Testing with a code that is in the bank (which must be sent to the user)

Example: http://localhost:1337/api/auth/reset-password/_code_here_

5) Request result

HTTP 200

HTTP 404

6) Displaying in documentation

If you don’t know how to add to swagger, read here.
:point_down:t4: :point_down:t4: :point_down:t4: :point_down:t4: :point_down:t4: