summaryrefslogtreecommitdiff
path: root/packages/backend/src/server/api/endpoints/email-address/available.ts
blob: 07064ce9fa61ea99be4f616ce62543a1a9c5372d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import define from '../../define.js';
import { validateEmailForAccount } from '@/services/validate-email-for-account.js';

export const meta = {
	tags: ['users'],

	requireCredential: false,

	res: {
		type: 'object',
		optional: false, nullable: false,
		properties: {
			available: {
				type: 'boolean',
				optional: false, nullable: false,
			},
			reason: {
				type: 'string',
				optional: false, nullable: true,
			},
		},
	},
} as const;

export const paramDef = {
	type: 'object',
	properties: {
		emailAddress: { type: 'string' },
	},
	required: ['emailAddress'],
} as const;

// eslint-disable-next-line import/no-default-export
export default define(meta, paramDef, async (ps) => {
	return await validateEmailForAccount(ps.emailAddress);
});