Новые глобабальные правки
This commit is contained in:
parent
b5b31f8a88
commit
36a3d37ad3
8 changed files with 35 additions and 26 deletions
|
|
@ -1,11 +1,11 @@
|
|||
import type { APIRoute } from 'astro';
|
||||
import { pb } from '../../../lib/pb';
|
||||
|
||||
export const POST: APIRoute = async ({ request, cookies }) => {
|
||||
export const POST: APIRoute = async ({ request, cookies, url }) => {
|
||||
try {
|
||||
const data = await request.json();
|
||||
|
||||
const { email, password } = data;
|
||||
const { email, password, redirect } = data;
|
||||
|
||||
if (!email || !password) {
|
||||
return new Response(JSON.stringify({
|
||||
|
|
@ -36,6 +36,12 @@ export const POST: APIRoute = async ({ request, cookies }) => {
|
|||
maxAge: 60 * 60 * 24 * 7,
|
||||
});
|
||||
|
||||
// Определяем URL для редиректа
|
||||
let redirectUrl = '/';
|
||||
if (redirect) {
|
||||
redirectUrl = redirect;
|
||||
}
|
||||
|
||||
return new Response(JSON.stringify({
|
||||
success: true,
|
||||
token: authData.token,
|
||||
|
|
@ -43,7 +49,8 @@ export const POST: APIRoute = async ({ request, cookies }) => {
|
|||
id: authData.record.id,
|
||||
name: authData.record.firstName,
|
||||
email: authData.record.email,
|
||||
}
|
||||
},
|
||||
redirect: redirectUrl
|
||||
}), { status: 200 });
|
||||
|
||||
} catch (error: any) {
|
||||
|
|
|
|||
|
|
@ -456,7 +456,11 @@ import { SITE_URL } from '@constants';
|
|||
const response = await fetch('/api/auth/sign-in', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ email, password }),
|
||||
body: JSON.stringify({
|
||||
email,
|
||||
password,
|
||||
redirect: new URLSearchParams(window.location.search).get('redirect')
|
||||
}),
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
|
|
@ -469,8 +473,14 @@ import { SITE_URL } from '@constants';
|
|||
// Сохраняем токен в куку для API
|
||||
document.cookie = `pb_auth=${data.token}; path=/; max-age=${7 * 24 * 60 * 60}; SameSite=Lax`;
|
||||
|
||||
// Перенаправляем в личный кабинет
|
||||
window.location.href = '/cabinet';
|
||||
// Перенаправляем на указанный URL или в личный кабинет
|
||||
const redirectUrl = data.redirect || '/cabinet';
|
||||
|
||||
// Если есть хэш с ID комментариев - добавляем его к URL
|
||||
const hash = new URLSearchParams(window.location.search).get('hash');
|
||||
const finalUrl = hash ? `${redirectUrl}#comments` : redirectUrl;
|
||||
|
||||
window.location.href = finalUrl;
|
||||
} else if (data.error?.includes('подтверждён')) {
|
||||
showError(emailInput, data.error);
|
||||
} else if (data.error?.includes('пароль')) {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
---
|
||||
import ArticleLayout from '@layouts/ArticleLayout.astro';
|
||||
import { SITE_URL } from '@constants';
|
||||
import Comments from '@components/blog/comments/Comments.astro';
|
||||
import Comments from '@components/blog/comments/Comments.tsx';
|
||||
import RelatedPosts from '@components/blog/RelatedPosts.astro';
|
||||
import ArticleTableOfContents from '@components/blog/ArticleTableOfContents.astro';
|
||||
import { getPostBySlug, getPosts, getPostImageUrl, getPostVotesStats } from '@lib/pb';
|
||||
|
|
@ -82,7 +82,7 @@ const heroImage = getPostImageUrl(post);
|
|||
|
||||
<!-- Система комментариев -->
|
||||
<div class="comments-wrapper">
|
||||
<Comments postSlug={post.slug} />
|
||||
<Comments postSlug={post.slug} client:load />
|
||||
</div>
|
||||
|
||||
<!-- Похожие статьи -->
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue