Set Android client

This checks user-agent before X-OmnivoreClient so the more explicit
X-OmnivoreClient overrides the derived client being set from user
agent.
This commit is contained in:
Jackson Harper
2024-07-05 20:15:20 +08:00
parent fbff86f48f
commit 180efb4846
3 changed files with 11 additions and 7 deletions

View File

@ -17,5 +17,7 @@ class Networker @Inject constructor(
private suspend fun authToken() = datastoreRepo.getString(omnivoreAuthToken) ?: ""
suspend fun authenticatedApolloClient() = ApolloClient.Builder().serverUrl(serverUrl())
.addHttpHeader("Authorization", value = authToken()).build()
.addHttpHeader("Authorization", value = authToken())
.addHttpHeader("X-OmnivoreClient", value = "android")
.build()
}

View File

@ -73,18 +73,19 @@ export const createApp = (): Express => {
// set client info in the request context
app.use(httpContext.middleware)
app.use('/api/', (req, res, next) => {
// get client info from header
const client = req.header('X-OmnivoreClient')
if (client) {
httpContext.set('client', client)
}
// get client info from user agent
const userAgent = req.header('User-Agent')
if (userAgent) {
const client = getClientFromUserAgent(userAgent)
httpContext.set('client', client)
}
// get client info from header
const client = req.header('X-OmnivoreClient')
if (client) {
httpContext.set('client', client)
}
next()
})

View File

@ -491,6 +491,7 @@ describe('auth router', () => {
return request
.post(`${route}/create-account`)
.set('X-OmnivoreClient', client)
.set('User-Agent', 'chrome')
.set('Cookie', [`pendingUserAuth=${pendingUserAuth}`])
.send({
name,