Skip to content

Commit

Permalink
fix: user login query
Browse files Browse the repository at this point in the history
  • Loading branch information
blackmann committed Dec 27, 2023
1 parent 9604b9b commit 14f96fe
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions base/src/authentication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,18 @@ async function baseAuthentication(app: App) {
}

const usersService = app.service('users') as CollectionService

const query: Record<string, string> = {}
if (ctx.data.username) {
query['username'] = ctx.data.username
} else {
query['email'] = ctx.data.email
}

const {
data: [user],
} = await usersService.collection.find({
query: {
// [ ] Support casting in $or queries
$or: [{ username: ctx.data.username }, { email: ctx.data.email }],
},
query,
})

if (!user) {
Expand Down Expand Up @@ -258,6 +263,7 @@ function checkAuth(): HookFn {
checkSecretKeyEnv()

const authHeader = ctx.headers['authorization']

if (authHeader) {
const [, token] = (authHeader as string).split(' ')
try {
Expand All @@ -275,7 +281,7 @@ function checkAuth(): HookFn {

ctx.user = user
} catch (err) {
console.log(err)
console.error('error checking auth', err)
//
}
}
Expand Down

0 comments on commit 14f96fe

Please sign in to comment.