无法使用 FaunaDB 中的特定用户登录
Unable to login with a specific user in FaunaDB
以前一直有效,但现在无效了。
我有一个限速逻辑,但即使我清除了所有限速数据,它仍然会发生。仅限特定用户。
我在 FaunaDB 上创建了另一个帐户用于测试目的和一个新数据库。如果我将旧数据库数据恢复到那个新数据库,一切正常!
所以我在旧的 FaunaDB 帐户上重新创建了整个数据库,但问题仍然存在。
有人遇到过类似的事情吗?
缓存中有信息吗?
Login(Match(Index("accounts_by_email"), "email@email.com"), {
password: "secret",
})
/* returns
Error: [
{
"position": [],
"code": "authentication failed",
"description": "The document was not found or provided password was incorrect."
}
]
*/
密码没有错误。它适用于其他 FaunaDB 帐户并恢复了数据。
./fdm -source path=backup -dest key={admin_key}
是的,这是一个临时问题。我在自己的 Fwitter 示例中的某个时刻体验到它很好。我们的唯一性检测不能很好地处理代码正在执行的一个复杂 FQL 流中 created/updated/deleted 事情的代码:)。我出票了,应该会同时修复。
很高兴知道其中的速率限制让我尝试了一些事件。它也可以写得更简单,我想我有点太深了,老实说……我当时刚加入 FaunaDB。我正在开发一个包含该更简单版本的框架应用程序。同时这里是代码:
更简单的速率限制
import { rateLimiting } from '../../fauna-queries/helpers/errors'
import faunadb from 'faunadb'
/*
* Ideally we limit the amount of calls that come to Login.
*/
const q = faunadb.query
const {
If,
Epoch,
Match,
Index,
Collection,
Let,
Var,
Paginate,
Select,
TimeDiff,
Or,
GTE,
Abort,
Create,
IsEmpty,
Count,
LT,
Do,
Now,
Subtract
} = q
function AddRateLimiting(action, FqlQueryToExecute, Identifier, calls, perMilliseconds) {
const ExecuteAndCreateLog = Do(
Create(Collection('logs'), {
data: {
action: action,
identity: Identifier
}
}),
FqlQueryToExecute
)
return Let(
{
logsPage: Paginate(Match(Index('logs_by_action_and_identity_ordered_by_ts'), action, Identifier), {
size: calls
})
},
If(
Or(IsEmpty(Var('logsPage')), LT(Count(Select(['data'], Var('logsPage'))), calls)),
// If no logs exist yet, create one.
ExecuteAndCreateLog,
Let(
{
// the page looks like { data: [timestamp1, timestamp2,...]},
// we will retrieve the last timestamp of that page. If the pagesize would be 3, it would be the oldest of these 3 events.
// since the index is ordered from new to old.
timestamp: Select(['data', Subtract(calls, 1)], Var('logsPage')),
// transform the Fauna timestamp to a Time object
time: Epoch(Var('timestamp'), 'microseconds'),
// How long ago was that event in ms
ageInMs: TimeDiff(Var('time'), Now(), 'milliseconds')
},
If(
GTE(Var('ageInMs'), perMilliseconds),
// Then great we execute
ExecuteAndCreateLog,
// Else.. Abort! Rate-limiting in action
Abort(rateLimiting)
)
)
)
)
}
错误登录后阻止
我还分开阻止了三个错误的登录,因为我有点 滥用 rate-limiting 系统。当然,此代码中有一些未定义,这只是为了让您了解它如何查找更多信息,请留意骨架 + 博客的出现。
// Let's wrap some other functionality around the login.
const BlockThreeFaultyLogins = Do(
If(
GTE(Count(Match(Index('logs_by_action_and_identity'), 'faulty_login', email)), MAX_LOGIN_ATTEMPTS),
// Abort if exceeded
Abort(tooManyFaultyLogins),
// Else, just continue as usual!
Let(
{
login: LoginFQL
},
Do(
If(
Equals(false, Var('login')),
// if the login is faulty, we'll add a log entry
Create(Collection('logs'), {
data: {
action: 'faulty_login',
identity: email
}
}),
// Else, we will clean up the faulty_login logs
q.Map(
Paginate(Match(Index('logs_by_action_and_identity'), 'faulty_login', email)),
Lambda(['logRef'], Delete(Var('logRef')))
)
),
Var('login')
)
)
)
)
以前一直有效,但现在无效了。
我有一个限速逻辑,但即使我清除了所有限速数据,它仍然会发生。仅限特定用户。
我在 FaunaDB 上创建了另一个帐户用于测试目的和一个新数据库。如果我将旧数据库数据恢复到那个新数据库,一切正常!
所以我在旧的 FaunaDB 帐户上重新创建了整个数据库,但问题仍然存在。
有人遇到过类似的事情吗? 缓存中有信息吗?
Login(Match(Index("accounts_by_email"), "email@email.com"), {
password: "secret",
})
/* returns
Error: [
{
"position": [],
"code": "authentication failed",
"description": "The document was not found or provided password was incorrect."
}
]
*/
密码没有错误。它适用于其他 FaunaDB 帐户并恢复了数据。
./fdm -source path=backup -dest key={admin_key}
是的,这是一个临时问题。我在自己的 Fwitter 示例中的某个时刻体验到它很好。我们的唯一性检测不能很好地处理代码正在执行的一个复杂 FQL 流中 created/updated/deleted 事情的代码:)。我出票了,应该会同时修复。
很高兴知道其中的速率限制让我尝试了一些事件。它也可以写得更简单,我想我有点太深了,老实说……我当时刚加入 FaunaDB。我正在开发一个包含该更简单版本的框架应用程序。同时这里是代码:
更简单的速率限制
import { rateLimiting } from '../../fauna-queries/helpers/errors'
import faunadb from 'faunadb'
/*
* Ideally we limit the amount of calls that come to Login.
*/
const q = faunadb.query
const {
If,
Epoch,
Match,
Index,
Collection,
Let,
Var,
Paginate,
Select,
TimeDiff,
Or,
GTE,
Abort,
Create,
IsEmpty,
Count,
LT,
Do,
Now,
Subtract
} = q
function AddRateLimiting(action, FqlQueryToExecute, Identifier, calls, perMilliseconds) {
const ExecuteAndCreateLog = Do(
Create(Collection('logs'), {
data: {
action: action,
identity: Identifier
}
}),
FqlQueryToExecute
)
return Let(
{
logsPage: Paginate(Match(Index('logs_by_action_and_identity_ordered_by_ts'), action, Identifier), {
size: calls
})
},
If(
Or(IsEmpty(Var('logsPage')), LT(Count(Select(['data'], Var('logsPage'))), calls)),
// If no logs exist yet, create one.
ExecuteAndCreateLog,
Let(
{
// the page looks like { data: [timestamp1, timestamp2,...]},
// we will retrieve the last timestamp of that page. If the pagesize would be 3, it would be the oldest of these 3 events.
// since the index is ordered from new to old.
timestamp: Select(['data', Subtract(calls, 1)], Var('logsPage')),
// transform the Fauna timestamp to a Time object
time: Epoch(Var('timestamp'), 'microseconds'),
// How long ago was that event in ms
ageInMs: TimeDiff(Var('time'), Now(), 'milliseconds')
},
If(
GTE(Var('ageInMs'), perMilliseconds),
// Then great we execute
ExecuteAndCreateLog,
// Else.. Abort! Rate-limiting in action
Abort(rateLimiting)
)
)
)
)
}
错误登录后阻止 我还分开阻止了三个错误的登录,因为我有点 滥用 rate-limiting 系统。当然,此代码中有一些未定义,这只是为了让您了解它如何查找更多信息,请留意骨架 + 博客的出现。
// Let's wrap some other functionality around the login.
const BlockThreeFaultyLogins = Do(
If(
GTE(Count(Match(Index('logs_by_action_and_identity'), 'faulty_login', email)), MAX_LOGIN_ATTEMPTS),
// Abort if exceeded
Abort(tooManyFaultyLogins),
// Else, just continue as usual!
Let(
{
login: LoginFQL
},
Do(
If(
Equals(false, Var('login')),
// if the login is faulty, we'll add a log entry
Create(Collection('logs'), {
data: {
action: 'faulty_login',
identity: email
}
}),
// Else, we will clean up the faulty_login logs
q.Map(
Paginate(Match(Index('logs_by_action_and_identity'), 'faulty_login', email)),
Lambda(['logRef'], Delete(Var('logRef')))
)
),
Var('login')
)
)
)
)