Added token authentication, organization module. Moved server bootstrapping code to server.ts file
This commit is contained in:
52
src/tokens/token.schema.ts
Normal file
52
src/tokens/token.schema.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
import { buildJsonSchemas } from "fastify-zod";
|
||||
import mongoose from "mongoose";
|
||||
import { z } from "zod";
|
||||
import { Claim } from "../utils/claims";
|
||||
|
||||
export const tokenModel = mongoose.model(
|
||||
"token",
|
||||
new mongoose.Schema({
|
||||
tenantId: String,
|
||||
pid: {
|
||||
type: String,
|
||||
unique: true,
|
||||
},
|
||||
name: String,
|
||||
claims: [],
|
||||
userId: mongoose.Types.ObjectId,
|
||||
hash: { type: String, required: true },
|
||||
createdAt: Date,
|
||||
})
|
||||
);
|
||||
|
||||
const tokenCore = {
|
||||
name: z.string().max(30),
|
||||
claims: z.array(z.string()).nonempty(),
|
||||
};
|
||||
|
||||
const createTokenInput = z.object({
|
||||
...tokenCore,
|
||||
});
|
||||
|
||||
const createTokenResponse = z.object({
|
||||
pid: z.string(),
|
||||
token: z.string(),
|
||||
...tokenCore,
|
||||
});
|
||||
|
||||
const getTokenResponse = z.object({
|
||||
pid: z.string(),
|
||||
name: z.string(),
|
||||
createdAt: z.string(),
|
||||
});
|
||||
|
||||
export type CreateTokenInput = z.infer<typeof createTokenInput>;
|
||||
|
||||
export const { schemas: tokenSchemas, $ref: $token } = buildJsonSchemas(
|
||||
{
|
||||
createTokenInput,
|
||||
createTokenResponse,
|
||||
getTokenResponse,
|
||||
},
|
||||
{ $id: "token" }
|
||||
);
|
||||
Reference in New Issue
Block a user