fix(cloud-sync): drop the previous account's cached tier when signing in as someone else
Switching accounts without a sign-out skipped resetToFree, and if the subscription lookup then failed the new account kept the old one's Pro badge and ad decision, persisted across restarts.
This commit is contained in:
parent
6fef05a39f
commit
9cf3fd7317
2 changed files with 31 additions and 2 deletions
|
|
@ -426,9 +426,13 @@ class CloudSyncService extends EventEmitter {
|
|||
|
||||
// 2) Supabase `subscriptions` 테이블에서 현재 티어 가져와 LicenseService에 동기화
|
||||
// (빅뱅 Phase 4 — 티어 enforcement)
|
||||
// 다른 계정으로 바로 바뀌는 경우엔 이전 계정의 캐시 티어를 먼저 버린다 — 조회가 실패하면
|
||||
// 이전 계정의 Pro 배지·광고 판정이 새 계정에 남고, 저장값이라 재시작 후에도 이어졌다.
|
||||
const switchedAccount = openUserId !== null && openUserId !== userId
|
||||
try {
|
||||
const tier = await this._fetchSubscriptionTier(userId)
|
||||
const { getLicenseService } = await import('./LicenseService')
|
||||
if (switchedAccount) getLicenseService().resetToFree()
|
||||
const tier = await this._fetchSubscriptionTier(userId)
|
||||
getLicenseService().syncFromCloud(tier)
|
||||
} catch (err) {
|
||||
logger.warn(
|
||||
|
|
|
|||
|
|
@ -53,6 +53,7 @@ const h = vi.hoisted(() => {
|
|||
const capture = vi.hoisted(() => ({
|
||||
meetingActive: false,
|
||||
events: [] as string[],
|
||||
license: [] as string[],
|
||||
}))
|
||||
|
||||
const spies = vi.hoisted(() => ({
|
||||
|
|
@ -140,7 +141,10 @@ vi.mock('../../../src/main/services/sync/settings-sync', () => ({
|
|||
vi.mock('../../../src/main/services/sync/audio-sync', () => ({ AUDIO_BUCKET: 'audio', listLocalAudioOwners: () => [] }))
|
||||
vi.mock('../../../src/main/windows/web-contents-hardening', () => ({ openExternalSafe: vi.fn(async () => true) }))
|
||||
vi.mock('../../../src/main/services/LicenseService', () => ({
|
||||
getLicenseService: () => ({ syncFromCloud: vi.fn(), resetToFree: vi.fn() }),
|
||||
getLicenseService: () => ({
|
||||
syncFromCloud: vi.fn(() => capture.license.push('sync')),
|
||||
resetToFree: vi.fn(() => capture.license.push('reset')),
|
||||
}),
|
||||
}))
|
||||
vi.mock('../../../src/main/services/VoiceModeService', () => ({
|
||||
getVoiceModeService: () => ({ isActive: false, cancelSession: vi.fn() }),
|
||||
|
|
@ -264,6 +268,27 @@ describe('CloudSyncService 세션 복원', () => {
|
|||
expect(h.state.currentUserId).toBe('user-1')
|
||||
})
|
||||
|
||||
it('다른 계정으로 로그인되면 티어 조회 전에 이전 계정의 캐시 티어를 버린다', async () => {
|
||||
h.state.currentUserId = 'user-0'
|
||||
capture.license = []
|
||||
writeStoredToken({ rt: 'rt-1', uid: 'user-1' })
|
||||
spies.refreshSession = vi.fn(async () => ({ data: { session: session() }, error: null }))
|
||||
|
||||
await getCloudSyncService().init()
|
||||
|
||||
expect(capture.license[0]).toBe('reset')
|
||||
})
|
||||
|
||||
it('같은 계정 복원은 캐시 티어를 버리지 않는다(오프라인이면 그대로 쓴다)', async () => {
|
||||
capture.license = []
|
||||
writeStoredToken({ rt: 'rt-1', uid: 'user-1' })
|
||||
spies.refreshSession = vi.fn(async () => ({ data: { session: session() }, error: null }))
|
||||
|
||||
await getCloudSyncService().init()
|
||||
|
||||
expect(capture.license).not.toContain('reset')
|
||||
})
|
||||
|
||||
it('같은 계정 복원은 진행 중인 녹음을 건드리지 않는다', async () => {
|
||||
capture.meetingActive = true
|
||||
capture.events = []
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue