๐Ÿ“ฆ TomDo1234 / payloadcms-encryption

๐Ÿ“„ payloadcms-encryption.ts ยท 15 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15import { FieldHook } from 'payload/types';

const encryptKey: FieldHook = ({ req, value }) => (value ? req.payload.encrypt(value as string) : undefined);
const decryptKey: FieldHook = ({ req, value }) => (value ? req.payload.decrypt(value as string) : undefined);

const encryptField = {
  beforeChange: [
    encryptKey,
  ],
  afterRead: [
    decryptKey,
  ],
};

export default encryptField;