I have the following FSL:
@role(role_refresh)
function refreshAccessToken() {
let user = Query.identity()
if(user != null && user isa User) {
// Delete Token to prevent reuse
Query.token()!.delete()
{
user: user,
token: createAccessAndRefreshToken(user)
}
}
}
But if I try to push it with the fauna cli via fauna schema push
I’m getting this error:
› Error: error: Type `{ *: Any } | Null` is not a subtype of `User`
› at src/lib/db/schema/fsl/functions/auth/tokens/refreshAccessToken.fsl:12:42
› |
› 12 | token: createAccessAndRefreshToken(user)
› | ^^^^
› |
The function createAccessAndRefreshToken
expects a prop of type User
, but I’m surprised, that
if(user != null && user isa User) { }
is not satisfying the validation. With Query.identity()!
I can get at least workaround the | Null
option, but I’m not able to find a workaround to classify it as User
.
Any help appreciated.
Besides of that, is there something similar to TypeScripts “as” keyword? I can guarantee that Query.identity() is not null and from type User as this will be already validated as part of the ABAC in role_refresh
, so it would be great to simply say Query.identity() as User