Skip to content
Discussion options

You must be logged in to vote

Here is an example using Payload's own ecrypt and decrypt functions.

// encryptionHooks.ts
import { 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 encryptionHooks = {
  beforeChange: [
    encryptKey,
  ],
  afterRead: [
    decryptKey,
  ],
};

export default encryptionHooks;

Example usage in a field:

import encryptionHooks from '../../fields/encryptionHooks';

const Customers: CollectionConfig = {
	slug: 'customers',
	fields: [
		{
			name: 'ssn',
			label: 'SSN',
			type: 't…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@kalib-code
Comment options

Answer selected by kalib-code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants