feat: integrate authentication and password management features, including bcrypt for hashing and NextAuth for session handling
This commit is contained in:
@@ -1,8 +1,12 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { accountService } from "@/services/account.service";
|
||||
import { requireAuth } from "@/lib/auth-utils";
|
||||
import type { Account } from "@/lib/types";
|
||||
|
||||
export async function POST(request: Request) {
|
||||
const authError = await requireAuth();
|
||||
if (authError) return authError;
|
||||
|
||||
try {
|
||||
const data: Omit<Account, "id"> = await request.json();
|
||||
const created = await accountService.create(data);
|
||||
@@ -17,6 +21,9 @@ export async function POST(request: Request) {
|
||||
}
|
||||
|
||||
export async function PUT(request: Request) {
|
||||
const authError = await requireAuth();
|
||||
if (authError) return authError;
|
||||
|
||||
try {
|
||||
const account: Account = await request.json();
|
||||
const updated = await accountService.update(account.id, account);
|
||||
@@ -31,6 +38,9 @@ export async function PUT(request: Request) {
|
||||
}
|
||||
|
||||
export async function DELETE(request: Request) {
|
||||
const authError = await requireAuth();
|
||||
if (authError) return authError;
|
||||
|
||||
try {
|
||||
const { searchParams } = new URL(request.url);
|
||||
const id = searchParams.get("id");
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { categoryService } from "@/services/category.service";
|
||||
import { requireAuth } from "@/lib/auth-utils";
|
||||
import type { Category } from "@/lib/types";
|
||||
|
||||
export async function POST(request: Request) {
|
||||
const authError = await requireAuth();
|
||||
if (authError) return authError;
|
||||
try {
|
||||
const data: Omit<Category, "id"> = await request.json();
|
||||
const created = await categoryService.create(data);
|
||||
@@ -17,6 +20,9 @@ export async function POST(request: Request) {
|
||||
}
|
||||
|
||||
export async function PUT(request: Request) {
|
||||
const authError = await requireAuth();
|
||||
if (authError) return authError;
|
||||
|
||||
try {
|
||||
const category: Category = await request.json();
|
||||
const updated = await categoryService.update(category.id, category);
|
||||
@@ -31,6 +37,9 @@ export async function PUT(request: Request) {
|
||||
}
|
||||
|
||||
export async function DELETE(request: Request) {
|
||||
const authError = await requireAuth();
|
||||
if (authError) return authError;
|
||||
|
||||
try {
|
||||
const { searchParams } = new URL(request.url);
|
||||
const id = searchParams.get("id");
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { folderService, FolderNotFoundError } from "@/services/folder.service";
|
||||
import { requireAuth } from "@/lib/auth-utils";
|
||||
import type { Folder } from "@/lib/types";
|
||||
|
||||
export async function POST(request: Request) {
|
||||
const authError = await requireAuth();
|
||||
if (authError) return authError;
|
||||
try {
|
||||
const data: Omit<Folder, "id"> = await request.json();
|
||||
const created = await folderService.create(data);
|
||||
@@ -17,6 +20,9 @@ export async function POST(request: Request) {
|
||||
}
|
||||
|
||||
export async function PUT(request: Request) {
|
||||
const authError = await requireAuth();
|
||||
if (authError) return authError;
|
||||
|
||||
try {
|
||||
const folder: Folder = await request.json();
|
||||
const updated = await folderService.update(folder.id, folder);
|
||||
@@ -31,6 +37,9 @@ export async function PUT(request: Request) {
|
||||
}
|
||||
|
||||
export async function DELETE(request: Request) {
|
||||
const authError = await requireAuth();
|
||||
if (authError) return authError;
|
||||
|
||||
try {
|
||||
const { searchParams } = new URL(request.url);
|
||||
const id = searchParams.get("id");
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { bankingService } from "@/services/banking.service";
|
||||
import { requireAuth } from "@/lib/auth-utils";
|
||||
|
||||
export async function GET() {
|
||||
const authError = await requireAuth();
|
||||
if (authError) return authError;
|
||||
|
||||
try {
|
||||
const data = await bankingService.getAllData();
|
||||
return NextResponse.json(data);
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import { requireAuth } from "@/lib/auth-utils";
|
||||
|
||||
export async function POST() {
|
||||
const authError = await requireAuth();
|
||||
if (authError) return authError;
|
||||
try {
|
||||
const result = await prisma.transaction.updateMany({
|
||||
where: {
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { transactionService } from "@/services/transaction.service";
|
||||
import { requireAuth } from "@/lib/auth-utils";
|
||||
import type { Transaction } from "@/lib/types";
|
||||
|
||||
export async function POST(request: Request) {
|
||||
const authError = await requireAuth();
|
||||
if (authError) return authError;
|
||||
try {
|
||||
const transactions: Transaction[] = await request.json();
|
||||
const result = await transactionService.createMany(transactions);
|
||||
@@ -17,6 +20,9 @@ export async function POST(request: Request) {
|
||||
}
|
||||
|
||||
export async function PUT(request: Request) {
|
||||
const authError = await requireAuth();
|
||||
if (authError) return authError;
|
||||
|
||||
try {
|
||||
const transaction: Transaction = await request.json();
|
||||
const updated = await transactionService.update(
|
||||
@@ -34,6 +40,9 @@ export async function PUT(request: Request) {
|
||||
}
|
||||
|
||||
export async function DELETE(request: Request) {
|
||||
const authError = await requireAuth();
|
||||
if (authError) return authError;
|
||||
|
||||
try {
|
||||
const { searchParams } = new URL(request.url);
|
||||
const id = searchParams.get("id");
|
||||
|
||||
Reference in New Issue
Block a user