Remove .env.local file and update middleware, page, and auth callback files to enhance logging and user experience. Translate comments and console logs to English for better clarity. Refactor Create Short URL form and Debug page for improved user feedback and error handling.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { createClient } from '@supabase/supabase-js';
|
||||
|
||||
// 从环境变量获取Supabase配置
|
||||
// Get Supabase configuration from environment variables
|
||||
const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL || process.env.SUPABASE_URL || '';
|
||||
const supabaseAnonKey = process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY || process.env.SUPABASE_ANON_KEY || '';
|
||||
|
||||
@@ -8,7 +8,7 @@ console.log('Supabase Configuration Check:', {
|
||||
urlDefined: !!supabaseUrl,
|
||||
keyDefined: !!supabaseAnonKey,
|
||||
url: supabaseUrl,
|
||||
// 打印部分key以便调试
|
||||
// Print partial key for debugging
|
||||
keyPrefix: supabaseAnonKey ? supabaseAnonKey.substring(0, 20) + '...' : 'undefined',
|
||||
keyLength: supabaseAnonKey ? supabaseAnonKey.length : 0
|
||||
});
|
||||
@@ -17,7 +17,7 @@ if (!supabaseUrl || !supabaseAnonKey) {
|
||||
console.error('Supabase URL and Anon Key are required');
|
||||
}
|
||||
|
||||
// 尝试解码JWT token并打印解码内容
|
||||
// Try to decode JWT token and print decoded content
|
||||
try {
|
||||
if (supabaseAnonKey) {
|
||||
const parts = supabaseAnonKey.split('.');
|
||||
@@ -30,10 +30,10 @@ try {
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('JWT解码失败:', error);
|
||||
console.error('JWT decoding failed:', error);
|
||||
}
|
||||
|
||||
// 创建自定义cookie处理逻辑
|
||||
// Create custom cookie handling logic
|
||||
const customStorage = {
|
||||
getItem: (key: string): string | null => {
|
||||
if (typeof document === 'undefined') return null;
|
||||
@@ -45,28 +45,28 @@ const customStorage = {
|
||||
setItem: (key: string, value: string): void => {
|
||||
if (typeof document === 'undefined') return;
|
||||
|
||||
// 获取当前主机和端口,处理localhost上的不同端口情况
|
||||
// Get current host and port to handle different ports on localhost
|
||||
const host = typeof window !== 'undefined' ? window.location.hostname : '';
|
||||
|
||||
// 设置cookie,对localhost使用通用domain
|
||||
// Set cookie, using generic domain for localhost
|
||||
document.cookie = `${key}=${value}; path=/; max-age=${60 * 60 * 24 * 7}; samesite=lax; domain=${host}`;
|
||||
|
||||
console.log(`Cookie ${key} 已设置,domain=${host}`);
|
||||
console.log(`Cookie ${key} has been set, domain=${host}`);
|
||||
},
|
||||
removeItem: (key: string): void => {
|
||||
if (typeof document === 'undefined') return;
|
||||
|
||||
// 获取当前主机和端口,处理localhost上的不同端口情况
|
||||
// Get current host and port to handle different ports on localhost
|
||||
const host = typeof window !== 'undefined' ? window.location.hostname : '';
|
||||
|
||||
// 删除cookie,对localhost使用通用domain
|
||||
// Remove cookie, using generic domain for localhost
|
||||
document.cookie = `${key}=; path=/; max-age=0; samesite=lax; domain=${host}`;
|
||||
|
||||
console.log(`Cookie ${key} 已移除`);
|
||||
console.log(`Cookie ${key} has been removed`);
|
||||
},
|
||||
};
|
||||
|
||||
// 创建Supabase客户端
|
||||
// Create Supabase client
|
||||
export const supabase = createClient(supabaseUrl, supabaseAnonKey, {
|
||||
auth: {
|
||||
persistSession: true,
|
||||
@@ -77,7 +77,7 @@ export const supabase = createClient(supabaseUrl, supabaseAnonKey, {
|
||||
}
|
||||
});
|
||||
|
||||
// 测试Supabase连接
|
||||
// Test Supabase connection
|
||||
supabase.auth.onAuthStateChange((event, session) => {
|
||||
console.log(`Supabase auth event: ${event}`, session ? 'Session exists' : 'No session');
|
||||
if (session) {
|
||||
@@ -85,7 +85,7 @@ supabase.auth.onAuthStateChange((event, session) => {
|
||||
}
|
||||
});
|
||||
|
||||
// 尝试执行健康检查
|
||||
// Try to perform health check
|
||||
async function checkSupabaseHealth() {
|
||||
try {
|
||||
const { data, error } = await supabase.from('_health').select('*').limit(1);
|
||||
|
||||
Reference in New Issue
Block a user