Skip to content

Commit 4cdce4c

Browse files
committed
feat: mobile redirector auth param support
1 parent b4195fe commit 4cdce4c

2 files changed

Lines changed: 56 additions & 1 deletion

File tree

__tests__/redirector.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,3 +150,56 @@ describe('GET /:id/profile-image', () => {
150150
.expect('Location', fallbackImages.avatar);
151151
});
152152
});
153+
154+
describe('GET /mobile', () => {
155+
const androidUA =
156+
'Mozilla/5.0 (Linux; Android 13; Pixel 7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Mobile Safari/537.36';
157+
const iosUA =
158+
'Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Mobile/15E148 Safari/604.1';
159+
160+
it('should redirect to Play Store for Android', async () => {
161+
const res = await request(app.server)
162+
.get('/mobile')
163+
.set('User-Agent', androidUA)
164+
.expect(307);
165+
166+
expect(res.headers.location).toContain('play.google.com');
167+
});
168+
169+
it('should redirect to App Store for iOS', async () => {
170+
const res = await request(app.server)
171+
.get('/mobile')
172+
.set('User-Agent', iosUA)
173+
.expect(307);
174+
175+
expect(res.headers.location).toContain('apps.apple.com');
176+
});
177+
178+
it('should redirect logged-in user to webapp by default', async () => {
179+
await saveFixtures(con, User, [{ id: '1', username: 'test' }]);
180+
181+
const res = await request(app.server)
182+
.get('/mobile')
183+
.set('User-Agent', androidUA)
184+
.set('authorization', `Service ${process.env.ACCESS_SECRET}`)
185+
.set('user-id', '1')
186+
.set('logged-in', 'true')
187+
.expect(307);
188+
189+
expect(res.headers.location).toBe('https://app.daily.dev');
190+
});
191+
192+
it('should skip auth redirect when auth=0', async () => {
193+
await saveFixtures(con, User, [{ id: '1', username: 'test' }]);
194+
195+
const res = await request(app.server)
196+
.get('/mobile?auth=0')
197+
.set('User-Agent', androidUA)
198+
.set('authorization', `Service ${process.env.ACCESS_SECRET}`)
199+
.set('user-id', '1')
200+
.set('logged-in', 'true')
201+
.expect(307);
202+
203+
expect(res.headers.location).toContain('play.google.com');
204+
});
205+
});

src/routes/redirects.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,9 @@ const redirectToMobile =
133133
const url = new URL(req.raw.url!, 'http://localhost');
134134
await sendRedirectAnalytics(con, req, res, '/mobile');
135135

136-
if (!!req.userId) {
136+
const skipAuth = url.searchParams.get('auth') === '0';
137+
138+
if (!skipAuth && !!req.userId) {
137139
return res.redirect(`https://app.daily.dev${url.search}`);
138140
}
139141

0 commit comments

Comments
 (0)