Добавлены новые зависимости, обновлены стили и улучшена структура проекта. Обновлен README с описанием функционала и технологий. Реализована анимация и адаптивный дизайн. Настроена авторизация с использованием Apollo Client.

This commit is contained in:
Bivekich
2025-07-16 18:00:41 +03:00
parent d260749bc9
commit 823ef9a28c
69 changed files with 15539 additions and 210 deletions

View File

@ -0,0 +1,65 @@
import { ApolloServer } from '@apollo/server'
import { startServerAndCreateNextHandler } from '@as-integrations/next'
import { NextRequest } from 'next/server'
import jwt from 'jsonwebtoken'
import { typeDefs } from '@/graphql/typedefs'
import { resolvers } from '@/graphql/resolvers'
// Интерфейс для контекста
interface Context {
user?: {
id: string
phone: string
}
}
// Создаем Apollo Server
const server = new ApolloServer<Context>({
typeDefs,
resolvers,
})
// Создаем Next.js handler
const handler = startServerAndCreateNextHandler<NextRequest>(server, {
context: async (req: NextRequest) => {
// Извлекаем токен из заголовка Authorization
const authHeader = req.headers.get('authorization')
const token = authHeader?.replace('Bearer ', '')
console.log('GraphQL Context - Auth header:', authHeader)
console.log('GraphQL Context - Token:', token ? `${token.substring(0, 20)}...` : 'No token')
if (!token) {
console.log('GraphQL Context - No token provided')
return { user: undefined }
}
try {
// Верифицируем JWT токен
const decoded = jwt.verify(token, process.env.JWT_SECRET!) as {
userId: string
phone: string
}
console.log('GraphQL Context - Decoded user:', { id: decoded.userId, phone: decoded.phone })
return {
user: {
id: decoded.userId,
phone: decoded.phone
}
}
} catch (error) {
console.error('GraphQL Context - Invalid token:', error)
return { user: undefined }
}
}
})
export async function GET(request: NextRequest) {
return handler(request)
}
export async function POST(request: NextRequest) {
return handler(request)
}