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
No known key found for this signature in database
2 changed files with 31 additions and 1 deletions

View File

@ -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

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());
}