WaspW
Wasp2y ago
abehod

How to overwrite system api endpoint?

Hello, I wanna use create custom auth/me endpoint handler, which would handle this request somehow differently, I have added this api to my main.wasp file, but when I make request to auth/me old handler is used. Is there a way to kind of overwrite system api endpoints?

My api in main.wasp:

api authMe {
  fn: import { authMe } from "@src/server/auth/authMe.js",
  entities: [User],
  httpRoute: (GET, "/auth/me")
}


My example authMe file:
import { serialize as superjsonSerialize } from 'superjson'
import { handleRejection } from 'wasp/server/utils'
import { throwInvalidCredentialsError } from 'wasp/auth/utils'

export const authMe = handleRejection(async (req, res) => {
  console.log("Custom authMe route");
  if (req.user) {
    return res.json(superjsonSerialize(req.user))
  } else {
    throwInvalidCredentialsError()
  }
})
Was this page helpful?