Новые изменения в систему регистрации
This commit is contained in:
parent
d69a7acd5a
commit
2391a3c7d6
2 changed files with 32 additions and 21 deletions
|
|
@ -1,6 +1,9 @@
|
|||
import type { APIRoute } from 'astro';
|
||||
import { pb } from '../../../lib/pb';
|
||||
|
||||
const POCKETBASE_URL = import.meta.env.POCKETBASE_URL || 'http://127.0.0.1:8090';
|
||||
const ADMIN_EMAIL = import.meta.env.PB_ADMIN_EMAIL || 'redibedi2019@gmail.com';
|
||||
const ADMIN_PASSWORD = import.meta.env.PB_ADMIN_PASSWORD || 'Stalin4444';
|
||||
|
||||
export const POST: APIRoute = async ({ request }) => {
|
||||
try {
|
||||
|
|
@ -43,21 +46,15 @@ export const POST: APIRoute = async ({ request }) => {
|
|||
error: 'Срок действия ссылки истёк'
|
||||
}), { status: 400 });
|
||||
}
|
||||
|
||||
console.log('Attempting admin auth...');
|
||||
await pb.collection('_superusers').authWithPassword(ADMIN_EMAIL, ADMIN_PASSWORD);
|
||||
console.log('Admin auth success, updating user...');
|
||||
|
||||
const response = await fetch(`${POCKETBASE_URL}/api/collections/users/records/${userId}`, {
|
||||
method: 'PATCH',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ verified: true }),
|
||||
await pb.collection('users').update(userId, {
|
||||
verified: true,
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const err = await response.json();
|
||||
console.error('Verify error:', err);
|
||||
return new Response(JSON.stringify({
|
||||
success: false,
|
||||
error: 'Не удалось подтвердить email'
|
||||
}), { status: 400 });
|
||||
}
|
||||
console.log('User verified:', userId);
|
||||
|
||||
return new Response(JSON.stringify({
|
||||
success: true,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue