mirror of
https://github.com/NoFxAiOS/nofx.git
synced 2026-07-16 09:11:03 +08:00
feat: crypto for key
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import React, { createContext, useContext, useState, useEffect } from 'react'
|
||||
import React, { createContext, useContext, useState, useEffect } from 'react';
|
||||
import { getSystemConfig } from '../lib/config';
|
||||
import { CryptoService } from '../lib/crypto';
|
||||
|
||||
interface User {
|
||||
id: string
|
||||
@@ -61,12 +63,33 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
|
||||
|
||||
const login = async (email: string, password: string) => {
|
||||
try {
|
||||
const systemConfig = await getSystemConfig()
|
||||
if (!systemConfig.rsa_public_key) {
|
||||
throw new Error('系统未配置登录所需的RSA公钥')
|
||||
}
|
||||
|
||||
await CryptoService.initialize(systemConfig.rsa_public_key)
|
||||
const sessionId = sessionStorage.getItem('session_id') || ''
|
||||
|
||||
const requestBody = {
|
||||
email_encrypted: await CryptoService.encryptSensitiveData(
|
||||
email,
|
||||
email,
|
||||
sessionId
|
||||
),
|
||||
password_encrypted: await CryptoService.encryptSensitiveData(
|
||||
password,
|
||||
email,
|
||||
sessionId
|
||||
),
|
||||
}
|
||||
|
||||
const response = await fetch('/api/login', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({ email, password }),
|
||||
body: JSON.stringify(requestBody),
|
||||
})
|
||||
|
||||
const data = await response.json()
|
||||
@@ -84,6 +107,7 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
|
||||
return { success: false, message: data.error }
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Login request failed:', error)
|
||||
return { success: false, message: '登录失败,请重试' }
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user