diff --git a/api/.env.example b/api/.env.example index 3f5257dc..7ef45abf 100644 --- a/api/.env.example +++ b/api/.env.example @@ -10,7 +10,7 @@ JWT_SECRET= # used to verify who's making the jwt JWT_ISSUER=$PUBLIC_URL # keibi's server to retrieve the public jwt secret -AUHT_SERVER=http://auth:4568 +AUTH_SERVER=http://auth:4568 IMAGES_PATH=./images diff --git a/api/src/auth.ts b/api/src/auth.ts index 02698625..f8b3638b 100644 --- a/api/src/auth.ts +++ b/api/src/auth.ts @@ -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()); +}