Commit a403b6ea authored by Grant's avatar Grant
Browse files

api: add admin dump-all-sessions

parent 3b2bb515
Loading
Loading
Loading
Loading
Loading
+12 −1
Original line number Diff line number Diff line
@@ -34,7 +34,7 @@ export class AuthSession {
    return sessions.map((d) => new AuthSession(d));
  }
  static async getActive(
    handle: `${string}@${string}`
    handle: `${string}@${string}`,
  ): Promise<AuthSession | null> {
    const session = await prisma.authSession.findFirst({
      where: {
@@ -49,6 +49,17 @@ export class AuthSession {

    return new AuthSession(session);
  }
  static async deleteAllForInstance(
    instance: string,
  ): Promise<{ count: number }> {
    const sessions = await prisma.authSession.deleteMany({
      where: {
        user_sub: { endsWith: "@" + instance },
      },
    });

    return sessions;
  }

  private _id: string;
  private _user_sub: `${string}@${string}`;
+13 −0
Original line number Diff line number Diff line
@@ -17,6 +17,19 @@ app.use((req, res, next) => {
  next();
});

app.post("/dump-all-sessions", async (req, res) => {
  if (!req.query.forInstance || typeof req.query.forInstance !== "string") {
    res.status(400).send("?forInstance is not specified");
    return;
  }

  const sessions = await AuthSession.deleteAllForInstance(
    req.query.forInstance,
  );

  res.json({ sessions });
});

/**
 * Create AuthSession for specified handle and send verification code to user
 * The created session is returned as a response