fixed redirect & schema

This commit is contained in:
ismail 2026-02-02 18:49:57 +01:00
parent 067c0d7a00
commit 6b1ffc1654
2 changed files with 42 additions and 3 deletions

View File

@ -66,6 +66,15 @@ CREATE TABLE IF NOT EXISTS products (
image_url VARCHAR(500),
show_on_homepage BOOLEAN DEFAULT FALSE,
brand VARCHAR(100),
stock_status ENUM('in_stock', 'out_of_stock', 'pre_order') DEFAULT 'in_stock',
width DECIMAL(10, 2),
height DECIMAL(10, 2),
depth DECIMAL(10, 2),
material VARCHAR(100),
color VARCHAR(50),
is_popular BOOLEAN DEFAULT FALSE,
is_new BOOLEAN DEFAULT FALSE,
is_trendy BOOLEAN DEFAULT FALSE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (category_id) REFERENCES categories(id) ON DELETE RESTRICT,
@ -95,6 +104,36 @@ CREATE TABLE IF NOT EXISTS product_images (
INDEX idx_product_id (product_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- 6c. Create conversations table (Messaging System)
CREATE TABLE IF NOT EXISTS conversations (
id INT AUTO_INCREMENT PRIMARY KEY,
user_id INT NOT NULL,
product_id INT,
subject VARCHAR(255) NOT NULL,
status ENUM('open', 'closed', 'archived') DEFAULT 'open',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,
FOREIGN KEY (product_id) REFERENCES products(id) ON DELETE SET NULL,
INDEX idx_user_id (user_id),
INDEX idx_product_id (product_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- 6d. Create messages table (Messaging System)
CREATE TABLE IF NOT EXISTS messages (
id INT AUTO_INCREMENT PRIMARY KEY,
conversation_id INT NOT NULL,
sender_id INT,
sender_role ENUM('customer', 'admin', 'system') DEFAULT 'customer',
content TEXT NOT NULL,
is_read BOOLEAN DEFAULT FALSE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (conversation_id) REFERENCES conversations(id) ON DELETE CASCADE,
FOREIGN KEY (sender_id) REFERENCES users(id) ON DELETE SET NULL,
INDEX idx_conversation_id (conversation_id),
INDEX idx_is_read (is_read)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- 7. Insert sample data
INSERT IGNORE INTO categories (id, name, description) VALUES
(1, 'Furniture', 'Chairs, tables, and other furniture'),

View File

@ -9,7 +9,7 @@ export async function GET(req: NextRequest) {
const code = searchParams.get('code');
if (!code) {
return NextResponse.redirect(new URL('/login?error=GoogleAuthFailed', req.url));
return NextResponse.redirect(new URL('/login?error=GoogleAuthFailed', process.env.NEXT_PUBLIC_APP_URL || req.url));
}
try {
@ -54,7 +54,7 @@ export async function GET(req: NextRequest) {
}, '7d'); // Long expiry for OAuth usually fine, or check rememberMe logic
// Redirect to a handling page on the frontend
const redirectUrl = new URL('/login', req.url);
const redirectUrl = new URL('/login', process.env.NEXT_PUBLIC_APP_URL || req.url);
redirectUrl.searchParams.set('token', token);
// Only pass essential auth data in the URL to protect PII
@ -73,6 +73,6 @@ export async function GET(req: NextRequest) {
return NextResponse.redirect(redirectUrl);
} catch (error) {
console.error('Google Auth Callback Error:', error);
return NextResponse.redirect(new URL('/login?error=GoogleAuthFailed', req.url));
return NextResponse.redirect(new URL('/login?error=GoogleAuthFailed', process.env.NEXT_PUBLIC_APP_URL || req.url));
}
}