-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathseed.ts
79 lines (72 loc) · 2.09 KB
/
seed.ts
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import { copycat } from '@snaplet/copycat';
import { createSeedClient } from '@snaplet/seed';
import { hash } from 'bcryptjs'; // Import bcrypt for hashing
async function main() {
const seed = await createSeedClient({ dryRun: true });
await seed.$resetDatabase();
const plainPassword = '123456';
const hashedPassword = await hash(plainPassword, 10); // Hash the password with bcrypt
// Seed users
const today = new Date();
const tomorrow = new Date(today);
tomorrow.setDate(tomorrow.getDate() + 1);
const yesterday = new Date(today);
yesterday.setDate(yesterday.getDate() - 1);
let { users } = await seed.users([
{
instance_id: '00000000-0000-0000-0000-000000000000',
email: '[email protected]',
banned_until: null,
role: 'authenticated',
aud: 'authenticated',
is_super_admin: false,
deleted_at: null,
encrypted_password: hashedPassword,
invited_at: null,
confirmation_token: '',
confirmation_sent_at: null,
recovery_token: '',
recovery_sent_at: null,
email_change_token_new: '',
email_change: '',
email_change_sent_at: null,
last_sign_in_at: null,
raw_app_meta_data: {
provider: 'email',
providers: ['email'],
},
raw_user_meta_data: {
name: 'jake',
email: '[email protected]',
},
},
]);
const additionalUsers = await seed.users((x) =>
x(10, {
email: (ctx) =>
copycat.email(ctx.seed, {
domain: 'acme.org',
}),
instance_id: '00000000-0000-0000-0000-000000000000',
banned_until: null,
role: 'authenticated',
aud: 'authenticated',
invited_at: null,
confirmation_token: null,
recovery_token: null,
is_super_admin: false,
deleted_at: null,
raw_app_meta_data: {
provider: 'email',
providers: ['email'],
},
//@ts-ignore
raw_user_meta_data: (ctx) => ({
name: ctx.data.email?.split('@')[0],
email: ctx.data.email,
}),
})
);
users = [...users, ...additionalUsers.users];
}
main().catch(console.error);