mirror of
https://github.com/memohai/Memoh.git
synced 2026-04-25 07:00:48 +09:00
fix: login
This commit is contained in:
@@ -76,11 +76,11 @@ export const validateUser = async (username: string, password: string) => {
|
||||
return null
|
||||
}
|
||||
|
||||
// 查询数据库中的用户
|
||||
// 查询数据库中的用户(使用 username 而不是 id)
|
||||
const [user] = await db
|
||||
.select()
|
||||
.from(users)
|
||||
.where(eq(users.id, userId!))
|
||||
.where(eq(users.username, username))
|
||||
|
||||
if (!user) {
|
||||
return null
|
||||
|
||||
@@ -7,11 +7,13 @@ import { createClient as createClientApi } from '@memohome/api/client'
|
||||
*/
|
||||
export function createClient(context?: MemoHomeContext) {
|
||||
const ctx = context || getContext()
|
||||
const storage = ctx.storage
|
||||
|
||||
const storage = ctx.storage
|
||||
|
||||
|
||||
const apiUrlResult = typeof storage.getApiUrl === 'function'
|
||||
? storage.getApiUrl()
|
||||
: (storage as unknown as Record<string, string>).apiUrl
|
||||
|
||||
|
||||
if (apiUrlResult instanceof Promise) {
|
||||
throw new Error('createClient does not support async storage. Use createClientAsync instead.')
|
||||
@@ -23,13 +25,16 @@ export function createClient(context?: MemoHomeContext) {
|
||||
? storage.getToken(ctx.currentUserId)
|
||||
: null
|
||||
|
||||
|
||||
// Handle async token retrieval
|
||||
if (token instanceof Promise) {
|
||||
throw new Error('createClient does not support async token storage. Use createClientAsync instead.')
|
||||
}
|
||||
|
||||
|
||||
const client = createClientApi(apiUrl, token ?? undefined)
|
||||
|
||||
|
||||
return client
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,6 @@ export async function handleLogin(ctx: Context) {
|
||||
await ctx.reply('❌ Unable to identify user')
|
||||
return
|
||||
}
|
||||
console.log('telegramUserId', telegramUserId)
|
||||
|
||||
// Parse command arguments
|
||||
const args = ctx.message && 'text' in ctx.message
|
||||
@@ -31,7 +30,6 @@ export async function handleLogin(ctx: Context) {
|
||||
|
||||
const [username, password] = args
|
||||
|
||||
try {
|
||||
const storage = await getTokenStorage(telegramUserId)
|
||||
|
||||
// Attempt login
|
||||
@@ -49,10 +47,6 @@ export async function handleLogin(ctx: Context) {
|
||||
} else {
|
||||
await ctx.reply('❌ Login failed: Invalid response from server')
|
||||
}
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : 'Unknown error'
|
||||
await ctx.reply(`❌ Login failed: ${message}`)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -35,7 +35,7 @@ export class TelegramPlatform extends BasePlatform {
|
||||
this.registerCommands()
|
||||
|
||||
// Start bot
|
||||
await this.bot.launch()
|
||||
this.bot.launch()
|
||||
console.log('✅ Telegram bot started successfully')
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,8 @@ import Redis from 'ioredis'
|
||||
|
||||
export const getTokenStorage = async (telegramUserId: string): Promise<TokenStorage> => {
|
||||
const redis = new Redis(process.env.REDIS_URL || 'redis://localhost:6379')
|
||||
const token = await redis.get(`memohome:telegram:${telegramUserId}:token`)
|
||||
const isExists = await redis.exists(`memohome:telegram:${telegramUserId}:token`)
|
||||
const token = isExists ? await redis.get(`memohome:telegram:${telegramUserId}:token`) : null
|
||||
return {
|
||||
getApiUrl: () => process.env.API_URL || 'http://localhost:7002',
|
||||
setApiUrl: () => {},
|
||||
|
||||
Reference in New Issue
Block a user