refactor: 个人自用,移除登录与云同步全链路
站点只给本人用,云乐坊 SSO 授权、收藏/历史云同步、获客归因和账号切换记账都没有收益,却被登录状态检查和同步失败提示持续打扰。 - 删除 useYunlefunAuth / yunlefunAuth / yunlefunSsoConfig / yunlefunAuth 适配器、useUserDataSync / userDataSync / userData 适配器、三个 client 插件与 /auth/callback 回调页 - 抽出 adapters/cloudbase.ts,让「反馈一下」和匿名筛选信号不再依赖登录态;cook-feedback 云函数保留 - 删除 cook-user-data 云函数与 cook_user_data 权限规则,移除 @yunlefun/sso 依赖 - 「我的」页删掉登录按钮、账号卡、四个统计格和退出登录;「关于」页删掉项目作者、致谢名单和上游宣传链接 - 本地收藏/历史与导出导入保留,删除同步专用的 lastUid 记账 取舍见 docs/decisions/0005-drop-login-and-sync.md
This commit is contained in:
@@ -1,15 +1,12 @@
|
||||
import type { RecipeItem } from '../apps/web/app/types'
|
||||
import type { DbRecipeItem } from '../apps/web/app/utils/db'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { createCloudbaseUserDataRemote, USER_DATA_FUNCTION } from '../apps/web/app/adapters/userData'
|
||||
import { favoriteEntries, setFavoriteEntries, toggleFavorite } from '../apps/web/app/composables/store/favorite'
|
||||
import { addRecipeHistory, clearRecipeHistories, recipeHistories, removeRecipeHistory } from '../apps/web/app/composables/store/history'
|
||||
import { exportLocalUserData, importLocalUserData, localUserData } from '../apps/web/app/composables/store/userData'
|
||||
import { exportLocalUserData, importLocalUserData } from '../apps/web/app/composables/store/userData'
|
||||
import { userDataMeta } from '../apps/web/app/composables/store/userDataMeta'
|
||||
|
||||
const NOW = 1_800_000_000_000
|
||||
|
||||
function recipe(name: string, id?: number): DbRecipeItem {
|
||||
function recipe(name: string, id?: number) {
|
||||
return { id, name, stuff: [], tools: [] }
|
||||
}
|
||||
|
||||
@@ -17,7 +14,7 @@ beforeEach(() => {
|
||||
vi.useFakeTimers({ now: NOW })
|
||||
setFavoriteEntries([])
|
||||
recipeHistories.value = []
|
||||
userDataMeta.value = { favoriteRemovals: [], historyRemovals: [], historyClearedAt: 0, lastUid: '' }
|
||||
userDataMeta.value = { favoriteRemovals: [], historyRemovals: [], historyClearedAt: 0 }
|
||||
return () => vi.useRealTimers()
|
||||
})
|
||||
|
||||
@@ -88,51 +85,3 @@ describe('export / import', () => {
|
||||
expect(favoriteEntries.value).toEqual([])
|
||||
})
|
||||
})
|
||||
|
||||
describe('localUserData', () => {
|
||||
it('only rewrites the last uid when it changes', () => {
|
||||
const before = userDataMeta.value
|
||||
localUserData.writeLastUid('')
|
||||
expect(userDataMeta.value).toBe(before)
|
||||
localUserData.writeLastUid('u1')
|
||||
expect(localUserData.readLastUid()).toBe('u1')
|
||||
})
|
||||
})
|
||||
|
||||
describe('createCloudbaseUserDataRemote', () => {
|
||||
const document = {
|
||||
version: 1 as const,
|
||||
favorites: [{ id: 1, time: NOW }],
|
||||
favoriteRemovals: [],
|
||||
histories: [{ recipe: { name: 'A', stuff: [], tools: [] } as RecipeItem, time: NOW }],
|
||||
historyRemovals: [],
|
||||
historyClearedAt: 0,
|
||||
updatedAt: NOW,
|
||||
}
|
||||
|
||||
it('reads through the cook-user-data function without naming a uid', async () => {
|
||||
const callFunction = vi.fn(async () => ({ ok: true, document: { favorites: [] } }))
|
||||
const remote = createCloudbaseUserDataRemote(callFunction)
|
||||
|
||||
await expect(remote.read('u1')).resolves.toEqual({ favorites: [] })
|
||||
expect(callFunction).toHaveBeenCalledWith(USER_DATA_FUNCTION, { action: 'get' })
|
||||
})
|
||||
|
||||
it('returns null when the account has no document', async () => {
|
||||
const remote = createCloudbaseUserDataRemote(async () => ({ ok: true, document: null }))
|
||||
await expect(remote.read('u1')).resolves.toBeNull()
|
||||
})
|
||||
|
||||
it('writes the whole document', async () => {
|
||||
const callFunction = vi.fn(async () => ({ ok: true, updatedAt: NOW }))
|
||||
await createCloudbaseUserDataRemote(callFunction).write('u1', document)
|
||||
expect(callFunction).toHaveBeenCalledWith(USER_DATA_FUNCTION, { action: 'set', document })
|
||||
})
|
||||
|
||||
it('surfaces function failures', async () => {
|
||||
const remote = createCloudbaseUserDataRemote(async () => ({ ok: false, code: 'LOGIN_REQUIRED' }))
|
||||
await expect(remote.read('u1')).rejects.toThrow('LOGIN_REQUIRED')
|
||||
await expect(remote.write('u1', document)).rejects.toThrow('LOGIN_REQUIRED')
|
||||
await expect(createCloudbaseUserDataRemote(async () => null).read('u1')).rejects.toThrow('unknown')
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user