-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_demo_users.js
More file actions
63 lines (55 loc) · 2.1 KB
/
Copy pathcreate_demo_users.js
File metadata and controls
63 lines (55 loc) · 2.1 KB
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
const SUPABASE_URL = "https://oioytzdvpeyfxcoglpzh.supabase.co"
const SERVICE_ROLE_KEY = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Im9pb3l0emR2cGV5Znhjb2dscHpoIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImlhdCI6MTc2MTg1NzMwMCwiZXhwIjoyMDc3NDMzMzAwfQ.6AZ-MT0WFa34jKmMtSrnhC3tNjXL2MFLKUQENALYRFo"
const users = [
{ email: "admin@restoflow.com", password: "admin123", full_name: "Yönetici", role: "admin" },
{ email: "cashier@restoflow.com", password: "cashier123", full_name: "Kasa Personeli", role: "cashier" },
{ email: "kitchen@restoflow.com", password: "kitchen123", full_name: "Mutfak Personeli", role: "kitchen" }
]
async function createUsers() {
for (const user of users) {
console.log(`Creating user: ${user.email}`)
// Create auth user
const authRes = await fetch(`${SUPABASE_URL}/auth/v1/admin/users`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${SERVICE_ROLE_KEY}`,
'Content-Type': 'application/json',
'apikey': SERVICE_ROLE_KEY
},
body: JSON.stringify({
email: user.email,
password: user.password,
email_confirm: true
})
})
const authData = await authRes.json()
if (authRes.ok) {
console.log(` ✓ Auth user created: ${authData.user.id}`)
// Create profile
const profileRes = await fetch(`${SUPABASE_URL}/rest/v1/profiles`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${SERVICE_ROLE_KEY}`,
'Content-Type': 'application/json',
'apikey': SERVICE_ROLE_KEY,
'Prefer': 'return=representation'
},
body: JSON.stringify({
id: authData.user.id,
full_name: user.full_name,
role: user.role
})
})
if (profileRes.ok) {
console.log(` ✓ Profile created`)
} else {
const error = await profileRes.text()
console.log(` ✗ Profile error: ${error}`)
}
} else {
console.log(` ✗ Auth error: ${authData.msg || JSON.stringify(authData)}`)
}
console.log('')
}
}
createUsers()