feat: modular domain driven boilerplate
This commit is contained in:
32
modules/identity/auth/principal.ts
Normal file
32
modules/identity/auth/principal.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { HttpAdapter, makeClient } from "@platform/relay";
|
||||
import { PrincipalProvider } from "@valkyr/auth";
|
||||
|
||||
import { config } from "../config.ts";
|
||||
import resolve from "../routes/identities/resolve/spec.ts";
|
||||
import { RoleSchema } from "../schemas/role.ts";
|
||||
|
||||
export const identity = makeClient(
|
||||
{
|
||||
adapter: new HttpAdapter({
|
||||
url: config.url,
|
||||
}),
|
||||
},
|
||||
{
|
||||
resolve: resolve.crypto({
|
||||
publicKey: config.internal.publicKey,
|
||||
}),
|
||||
},
|
||||
);
|
||||
|
||||
export const principal = new PrincipalProvider(RoleSchema, {}, async function (id: string) {
|
||||
const response = await identity.resolve({ params: { id } });
|
||||
if ("data" in response) {
|
||||
return {
|
||||
id,
|
||||
roles: response.data.roles,
|
||||
attributes: {},
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
export type Principal = typeof principal.$principal;
|
||||
Reference in New Issue
Block a user