Add function to fetch user info from api

This commit is contained in:
Zoe Roux
2025-04-06 23:26:29 +02:00
parent aa9476680c
commit a7f355531d
2 changed files with 31 additions and 1 deletions
+30
View File
@@ -69,3 +69,33 @@ export const auth = new Elysia({ name: "auth" })
},
})
.as("plugin");
const User = t.Object({
id: t.String({ format: "uuid" }),
username: t.String(),
email: t.String({ format: "email" }),
createdDate: t.String({ format: "date-time" }),
lastSeen: t.String({ format: "date-time" }),
claims: t.Record(t.String(), t.Any()),
oidc: t.Record(
t.String(),
t.Object({
id: t.String({ format: "uuid" }),
username: t.String(),
profileUrl: t.Nullable(t.String({ format: "url" })),
}),
),
});
const UserC = TypeCompiler.Compile(User);
export async function getUserInfo(
id: string,
headers: { authorization: string },
) {
const resp = await fetch(
new URL(`/auth/users/${id}`, process.env.AUTH_SERVER ?? "http://auth:4568"),
{ headers },
);
return UserC.Decode(await resp.json());
}