Refactor: Implement DashboardLayout, fix mobile nav, and resolve scroll issues
This commit is contained in:
25
app/api/auth/send/route.ts
Normal file
25
app/api/auth/send/route.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import TelegramBot from 'node-telegram-bot-api';
|
||||
import { generateOTP, saveOTP } from '@/lib/otp';
|
||||
|
||||
export async function POST() {
|
||||
const token = process.env.TELEGRAM_BOT_TOKEN;
|
||||
const chatId = process.env.TELEGRAM_CHAT_ID;
|
||||
|
||||
if (!token || !chatId) {
|
||||
console.error("Telegram credentials missing");
|
||||
return NextResponse.json({ error: 'Telegram not configured' }, { status: 500 });
|
||||
}
|
||||
|
||||
const otp = generateOTP();
|
||||
saveOTP(otp);
|
||||
|
||||
const bot = new TelegramBot(token, { polling: false });
|
||||
try {
|
||||
await bot.sendMessage(chatId, `🔐 Your Login Code: ${otp}`);
|
||||
return NextResponse.json({ success: true });
|
||||
} catch (error: any) {
|
||||
console.error('Telegram Error:', error);
|
||||
return NextResponse.json({ error: 'Failed to send message: ' + error.message }, { status: 500 });
|
||||
}
|
||||
}
|
||||
24
app/api/auth/verify/route.ts
Normal file
24
app/api/auth/verify/route.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import { verifyOTP } from '@/lib/otp';
|
||||
import { cookies } from 'next/headers';
|
||||
|
||||
export async function POST(req: Request) {
|
||||
try {
|
||||
const { code } = await req.json();
|
||||
|
||||
if (verifyOTP(code)) {
|
||||
// Set cookie
|
||||
cookies().set('auth_token', 'true', {
|
||||
httpOnly: true,
|
||||
secure: process.env.NODE_ENV === 'production',
|
||||
maxAge: 60 * 60 * 24 * 7, // 1 week
|
||||
path: '/'
|
||||
});
|
||||
return NextResponse.json({ success: true });
|
||||
}
|
||||
|
||||
return NextResponse.json({ error: 'Invalid Code' }, { status: 401 });
|
||||
} catch (error) {
|
||||
return NextResponse.json({ error: 'Invalid Request' }, { status: 400 });
|
||||
}
|
||||
}
|
||||
17
app/api/sync/route.ts
Normal file
17
app/api/sync/route.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import { getDatabase, saveDatabase } from '@/lib/server-db';
|
||||
|
||||
export async function GET() {
|
||||
const data = getDatabase();
|
||||
return NextResponse.json(data);
|
||||
}
|
||||
|
||||
export async function POST(req: Request) {
|
||||
try {
|
||||
const body = await req.json();
|
||||
saveDatabase(body);
|
||||
return NextResponse.json({ success: true });
|
||||
} catch (error) {
|
||||
return NextResponse.json({ error: 'Invalid Data' }, { status: 400 });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user