({ request }: LoaderFunctionArgs)
| 7 | import { authenticateApiRequestWithPersonalAccessToken } from "~/services/personalAccessToken.server"; |
| 8 | |
| 9 | export async function loader({ request }: LoaderFunctionArgs) { |
| 10 | logger.info("whoami v2", { url: request.url }); |
| 11 | try { |
| 12 | const authenticationResult = await authenticateApiRequestWithPersonalAccessToken(request); |
| 13 | if (!authenticationResult) { |
| 14 | return json({ error: "Invalid or Missing Access Token" }, { status: 401 }); |
| 15 | } |
| 16 | |
| 17 | const user = await prisma.user.findUnique({ |
| 18 | select: { |
| 19 | email: true, |
| 20 | }, |
| 21 | where: { |
| 22 | id: authenticationResult.userId, |
| 23 | }, |
| 24 | }); |
| 25 | |
| 26 | if (!user) { |
| 27 | return json({ error: "User not found" }, { status: 404 }); |
| 28 | } |
| 29 | |
| 30 | const result: WhoAmIResponse = { |
| 31 | userId: authenticationResult.userId, |
| 32 | email: user.email, |
| 33 | dashboardUrl: env.APP_ORIGIN, |
| 34 | }; |
| 35 | return json(result); |
| 36 | } catch (error) { |
| 37 | const errorMessage = error instanceof Error ? error.message : "Something went wrong"; |
| 38 | logger.error("Error in whoami v2", { error: errorMessage }); |
| 39 | return json({ error: errorMessage }, { status: 400 }); |
| 40 | } |
| 41 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…