Skip to content

use Wasp's new Custom Env Var validation schema for validating integrations #483

@vincanger

Description

@vincanger

We currently use a custom env var validation setup but should refactor everything and add validation using Wasp's custom env var vailidation logic, e.g. :

  server: {
    envValidationSchema: import { envValidationSchema } from "@src/server/validation",
  },
// `src/file-upload/validation.ts`

export const fileUploadEnvValidationSchema = z.object({
  AWS_S3_REGION: z.string({ required_error: 'AWS_S3_REGION is required' }),
  AWS_S3_FILES_BUCKET: z.string({ required_error: 'AWS_S3_FILES_BUCKET is required' }),
  AWS_S3_IAM_ACCESS_KEY: z.string({ required_error: 'AWS_S3_IAM_ACCESS_KEY is required' }).regex(/^[A-Z0-9]+$/, 'Invalid AWS IAM access key'),
  AWS_S3_IAM_SECRET_KEY: z.string({ required_error: 'AWS_S3_IAM_SECRET_KEY is required' }).regex(/^[A-Za-z0-9/+=]+$/, 'Invalid AWS IAM secret key'),
});
// `src/server/validation.ts

import { defineEnvValidationSchema } from 'wasp/env';
import { fileUploadEnvValidationSchema } from '../file-upload/validation';

export const envValidationSchema = defineEnvValidationSchema(z.object({
  ...fileUploadEnvValidationSchema.shape,
}));
AWS_S3_IAM_ACCESS_KEY=EXAMPLEACCE55KEY
AWS_S3_IAM_SECRET_KEY=example+Secr3tK3y
AWS_S3_FILES_BUCKET=your-bucket-name
AWS_S3_REGION=your-region

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions