+
+
{/* Navigation */}
{isAuthenticated ? (
<>
-
+
Welcome, {user?.email}
- {/* Main Content */}
-
-
-
- 分布式流星监测网络
-
-
- Distributed Meteor Monitoring Network
-
-
- {!isAuthenticated && (
-
-
+
+ )}
)
}
diff --git a/meteor-web-backend/scripts/create-premium-user.js b/meteor-web-backend/scripts/create-premium-user.js
new file mode 100644
index 0000000..00072de
--- /dev/null
+++ b/meteor-web-backend/scripts/create-premium-user.js
@@ -0,0 +1,136 @@
+#!/usr/bin/env node
+
+/**
+ * 创建付费测试用户的脚本
+ *
+ * 使用方法:
+ * node scripts/create-premium-user.js [email] [password] [displayName]
+ *
+ * 例子:
+ * node scripts/create-premium-user.js premium@test.com TestPass123 "Premium User"
+ */
+
+const { Client } = require('pg');
+const path = require('path');
+require('dotenv').config({ path: path.join(__dirname, '..', '.env') });
+
+async function createPremiumUser(email, password, displayName) {
+ const client = new Client({
+ connectionString: process.env.DATABASE_URL
+ });
+
+ try {
+ await client.connect();
+ console.log('✅ Connected to database');
+
+ // 1. 首先注册普通用户
+ console.log(`\n📝 Registering user: ${email}`);
+
+ const registerResponse = await fetch('http://localhost:3001/api/v1/auth/register-email', {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ },
+ body: JSON.stringify({
+ email,
+ password,
+ displayName
+ })
+ });
+
+ if (!registerResponse.ok) {
+ const error = await registerResponse.json();
+ throw new Error(`Registration failed: ${error.message}`);
+ }
+
+ const registerData = await registerResponse.json();
+ const userId = registerData.userId;
+
+ console.log(`✅ User registered successfully with ID: ${userId}`);
+
+ // 2. 更新用户为付费用户
+ const fakeCustomerId = 'cus_test_premium_' + Date.now();
+ const fakeSubscriptionId = 'sub_test_premium_' + Date.now();
+
+ const updateQuery = `
+ UPDATE user_profiles
+ SET
+ payment_provider_customer_id = $1,
+ payment_provider_subscription_id = $2,
+ updated_at = NOW()
+ WHERE id = $3
+ `;
+
+ const result = await client.query(updateQuery, [fakeCustomerId, fakeSubscriptionId, userId]);
+
+ if (result.rowCount > 0) {
+ console.log('✅ User upgraded to premium successfully!');
+
+ // 3. 测试登录和profile获取
+ console.log('\n🔐 Testing login...');
+ const loginResponse = await fetch('http://localhost:3001/api/v1/auth/login-email', {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ },
+ body: JSON.stringify({
+ email,
+ password
+ })
+ });
+
+ if (loginResponse.ok) {
+ const loginData = await loginResponse.json();
+ console.log('✅ Login successful');
+
+ // 测试profile
+ const profileResponse = await fetch('http://localhost:3001/api/v1/auth/profile', {
+ method: 'GET',
+ headers: {
+ 'Authorization': `Bearer ${loginData.accessToken}`,
+ 'Content-Type': 'application/json',
+ }
+ });
+
+ if (profileResponse.ok) {
+ const profileData = await profileResponse.json();
+ console.log('✅ Profile retrieved successfully');
+
+ console.log('\n🎉 Premium user created successfully!');
+ console.log('='.repeat(50));
+ console.log(`👤 User Details:`);
+ console.log(` Email: ${email}`);
+ console.log(` Password: ${password}`);
+ console.log(` Display Name: ${displayName}`);
+ console.log(` User ID: ${userId}`);
+ console.log(` Customer ID: ${fakeCustomerId}`);
+ console.log(` Subscription ID: ${fakeSubscriptionId}`);
+ console.log(` Subscription Status: ${profileData.subscriptionStatus}`);
+ console.log(` Has Active Subscription: ${profileData.hasActiveSubscription}`);
+ console.log('='.repeat(50));
+ }
+ }
+ } else {
+ console.log('❌ Failed to upgrade user to premium');
+ }
+
+ } catch (error) {
+ console.error('❌ Error:', error.message);
+ process.exit(1);
+ } finally {
+ await client.end();
+ }
+}
+
+// 命令行参数处理
+const args = process.argv.slice(2);
+const email = args[0] || 'premium' + Date.now() + '@test.com';
+const password = args[1] || 'TestPassword123';
+const displayName = args[2] || 'Premium User';
+
+console.log('🚀 Creating Premium User...');
+console.log(`Email: ${email}`);
+console.log(`Password: ${password}`);
+console.log(`Display Name: ${displayName}`);
+
+createPremiumUser(email, password, displayName);
\ No newline at end of file
diff --git a/test-api.js b/test-api.js
new file mode 100644
index 0000000..85b3359
--- /dev/null
+++ b/test-api.js
@@ -0,0 +1,30 @@
+const fetch = require('node-fetch');
+
+async function testAPI() {
+ try {
+ console.log('Testing register-email API...');
+
+ const response = await fetch('http://localhost:3001/api/v1/auth/register-email', {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ },
+ body: JSON.stringify({
+ email: 'testuser@example.com',
+ password: 'TestPass123',
+ displayName: 'Test User'
+ })
+ });
+
+ console.log('Response status:', response.status);
+ console.log('Response headers:', Object.fromEntries(response.headers));
+
+ const data = await response.text();
+ console.log('Response body:', data);
+
+ } catch (error) {
+ console.error('Error:', error.message);
+ }
+}
+
+testAPI();
\ No newline at end of file