feat: 添加用户认证功能,包括登录、注册、GitHub/Gitee OAuth集成及相关路由配置。
This commit is contained in:
@@ -178,6 +178,38 @@ export async function handleGitHubCallback(code: string): Promise<{ user: User;
|
||||
throw new Error('GitHub authentication failed');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Gitee OAuth login URL
|
||||
*/
|
||||
export function getGiteeLoginUrl(state?: string): string {
|
||||
const isLocal = window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1';
|
||||
const baseUrl = isLocal
|
||||
? (import.meta.env.VITE_API_BASE_URL || 'http://localhost:2612/api/v1')
|
||||
: '/api/v1';
|
||||
|
||||
console.log('[Auth] Generating Gitee URL with base:', baseUrl);
|
||||
|
||||
let fullUrlString;
|
||||
if (baseUrl.startsWith('/')) {
|
||||
fullUrlString = `${window.location.origin}${baseUrl}/auth/gitee`;
|
||||
} else {
|
||||
fullUrlString = `${baseUrl}/auth/gitee`;
|
||||
}
|
||||
|
||||
const url = new URL(fullUrlString);
|
||||
if (state) {
|
||||
url.searchParams.append('state', state);
|
||||
}
|
||||
return url.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirect to Gitee OAuth login
|
||||
*/
|
||||
export function loginWithGitee(state?: string): void {
|
||||
window.location.href = getGiteeLoginUrl(state);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current user information
|
||||
*/
|
||||
@@ -215,6 +247,8 @@ export default {
|
||||
loginWithGitHub,
|
||||
getGitHubLoginUrl,
|
||||
handleGitHubCallback,
|
||||
loginWithGitee,
|
||||
getGiteeLoginUrl,
|
||||
getCurrentUser,
|
||||
updatePassword,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user