fix(webui): prevent infinite redirect loop between /signup and /login

This commit is contained in:
yiling
2026-06-08 16:08:41 +08:00
parent 22e0f95748
commit 5333d17c7c
2 changed files with 26 additions and 25 deletions
+25 -25
View File
@@ -26,13 +26,13 @@ describe('LruTtlCache', () => {
const cache = new LruTtlCache<string, string>(2) const cache = new LruTtlCache<string, string>(2)
cache.set('key1', 'value1', 1000) cache.set('key1', 'value1', 1000)
cache.set('key2', 'value2', 1000) cache.set('key2', 'value2', 1000)
// Access key1 to make it most recently used // Access key1 to make it most recently used
cache.get('key1') cache.get('key1')
// Add key3, which should evict key2 (the least recently used) // Add key3, which should evict key2 (the least recently used)
cache.set('key3', 'value3', 1000) cache.set('key3', 'value3', 1000)
expect(cache.get('key1')).toBe('value1') expect(cache.get('key1')).toBe('value1')
expect(cache.get('key2')).toBeUndefined() expect(cache.get('key2')).toBeUndefined()
expect(cache.get('key3')).toBe('value3') expect(cache.get('key3')).toBe('value3')
@@ -41,9 +41,9 @@ describe('LruTtlCache', () => {
it('should return undefined for expired items', () => { it('should return undefined for expired items', () => {
const cache = new LruTtlCache<string, string>(10) const cache = new LruTtlCache<string, string>(10)
cache.set('key1', 'value1', 1000) cache.set('key1', 'value1', 1000)
vi.advanceTimersByTime(1001) vi.advanceTimersByTime(1001)
expect(cache.get('key1')).toBeUndefined() expect(cache.get('key1')).toBeUndefined()
expect(cache.size).toBe(0) expect(cache.size).toBe(0)
}) })
@@ -51,28 +51,28 @@ describe('LruTtlCache', () => {
it('should proactively evict expired items on get', () => { it('should proactively evict expired items on get', () => {
const sampleSize = 5 const sampleSize = 5
const cache = new LruTtlCache<string, string>(100, sampleSize) const cache = new LruTtlCache<string, string>(100, sampleSize)
// Set 10 items, all will expire // Set 10 items, all will expire
for (let i = 0; i < 10; i++) { for (let i = 0; i < 10; i++) {
cache.set(`key${i}`, `value${i}`, 1000) cache.set(`key${i}`, `value${i}`, 1000)
} }
// Add one item that stays valid // Add one item that stays valid
cache.set('valid', 'validValue', 5000) cache.set('valid', 'validValue', 5000)
// Advance time so the 10 items expire // Advance time so the 10 items expire
vi.advanceTimersByTime(1001) vi.advanceTimersByTime(1001)
// Total size should still be 11 (lazy eviction) // Total size should still be 11 (lazy eviction)
expect(cache.size).toBe(11) expect(cache.size).toBe(11)
// Call get on the valid item once. It should trigger one evictSample call. // Call get on the valid item once. It should trigger one evictSample call.
// evictSample will check 5 items. // evictSample will check 5 items.
cache.get('valid') cache.get('valid')
// Size should now be 11 - 5 = 6 // Size should now be 11 - 5 = 6
expect(cache.size).toBe(6) expect(cache.size).toBe(6)
// Call get again, it should evict the remaining 5 expired items // Call get again, it should evict the remaining 5 expired items
cache.get('valid') cache.get('valid')
expect(cache.size).toBe(1) expect(cache.size).toBe(1)
@@ -82,23 +82,23 @@ describe('LruTtlCache', () => {
it('should loop through the cache with proactive eviction', () => { it('should loop through the cache with proactive eviction', () => {
// sampleSize = 3 to make sure we cover all items in one go or skip k3 correctly // sampleSize = 3 to make sure we cover all items in one go or skip k3 correctly
const cache = new LruTtlCache<string, string>(10, 3) const cache = new LruTtlCache<string, string>(10, 3)
cache.set('k1', 'v1', 1000) cache.set('k1', 'v1', 1000)
cache.set('k2', 'v2', 1000) cache.set('k2', 'v2', 1000)
cache.set('k3', 'v3', 5000) cache.set('k3', 'v3', 5000)
vi.advanceTimersByTime(1001) vi.advanceTimersByTime(1001)
// First get: evicts k1, k2. Checks k3 (not expired). // First get: evicts k1, k2. Checks k3 (not expired).
cache.get('k3') cache.get('k3')
expect(cache.size).toBe(1) expect(cache.size).toBe(1)
// Add more items // Add more items
cache.set('k4', 'v4', 1000) cache.set('k4', 'v4', 1000)
cache.set('k5', 'v5', 1000) cache.set('k5', 'v5', 1000)
vi.advanceTimersByTime(1001) vi.advanceTimersByTime(1001)
// Second get: evicts k4, k5. // Second get: evicts k4, k5.
cache.get('k3') cache.get('k3')
expect(cache.size).toBe(1) expect(cache.size).toBe(1)
@@ -127,25 +127,25 @@ describe('LruTtlCache', () => {
// This test addresses the user's specific request: // This test addresses the user's specific request:
// "add 100 keys to cache, do a evictSample, and remove 99 keys manually, and do evictSample again, see what happen" // "add 100 keys to cache, do a evictSample, and remove 99 keys manually, and do evictSample again, see what happen"
const cache = new LruTtlCache<number, number>(200, 10) const cache = new LruTtlCache<number, number>(200, 10)
// Add 100 keys // Add 100 keys
for (let i = 0; i < 100; i++) { for (let i = 0; i < 100; i++) {
cache.set(i, i, 10000) cache.set(i, i, 10000)
} }
// Initial get to trigger evictSample and initialize the iterator // Initial get to trigger evictSample and initialize the iterator
cache.get(999) cache.get(999)
// Remove 99 keys manually (leaving key 99) // Remove 99 keys manually (leaving key 99)
for (let i = 0; i < 99; i++) { for (let i = 0; i < 99; i++) {
cache.delete(i) cache.delete(i)
} }
expect(cache.size).toBe(1) expect(cache.size).toBe(1)
// Advance time so the remaining key 99 would expire if it was checked // Advance time so the remaining key 99 would expire if it was checked
vi.advanceTimersByTime(20000) vi.advanceTimersByTime(20000)
// Call get. evictSample should run. // Call get. evictSample should run.
// The iterator was pointing to something that was deleted. // The iterator was pointing to something that was deleted.
// It should proceed to the next available element (key 99) and evict it. // It should proceed to the next available element (key 99) and evict it.
cache.get(999) cache.get(999)
+1
View File
@@ -11,6 +11,7 @@ const customFetch = async (input: RequestInfo | URL, init?: RequestInit) => {
// Don't redirect if we are already on login page, it's an auth request, or we are on a public share page // Don't redirect if we are already on login page, it's an auth request, or we are on a public share page
if ( if (
!window.location.pathname.includes('/login') && !window.location.pathname.includes('/login') &&
!window.location.pathname.includes('/signup') &&
!window.location.pathname.startsWith('/share/') && !window.location.pathname.startsWith('/share/') &&
!url.includes('/api/authn') !url.includes('/api/authn')
) { ) {