Open rimselis opened 1 year ago
Experiencing the same issue on 2.0.0-beta.32. Same blitz version output as @rimselis
Tested it from blitz@2.0.0-beta.28
to blitz@2.0.0-beta.32
. Issue happens only on blitz@2.0.0-beta.32
.
Same issue on 2.0.0-beta.32.
Tested downgrading to blitz@2.0.0-beta.28 as commented by Rimselis, and also .beta-31. In both appear but the expected message "Error: You are not authenticated"
Hey @rimselis, could you add an explicit Superjson registration in your blitz-sever.ts file and check.
//blitz-server.ts
...
SuperJson.registerClass(AuthenticationError, {
identifier: "BlitzAuthenticationError",
allowProps: ["name", "message", "code", "statusCode", "meta", "url"],
})
I'm on 2.0.0-beta.33
and am still getting a 400
instead of the expected 401 AuthenticationError
. This only occurs in my production env and not in local dev.
This occurs when I am using resolver.authorize(Role.Admin)
for example.
Are you sure it was fixed @rodobre ? This is what I see instead of the expected error fallback:
~I am seeing the same issue. For some reason it only happens on my machine, and doesn't happen in production on Vercel.~ Upgrading to beta.33 fixes the issue. @mjyoung Did you make sure to update all blitz packages ? The fix is in the RPC package.
Yes, all packages are updated to 2.0.0-beta.33:
"@blitzjs/auth": "2.0.0-beta.33",
"@blitzjs/next": "2.0.0-beta.33",
"@blitzjs/rpc": "2.0.0-beta.33",
The initial issue seems to be fixed with 2.0.0-beta.33
(checked both with resolver.authorize()
and with ctx.session.$authorize()
) on the same fresh project. Thank you!
Not sure if I should close this as there are open questions in the comments.
Not sure what I'm doing wrong then. I'm on 2.0.0-beta.33
and in production, my error boundaries do not trigger on instanceof AuthenticationError
and instanceof AuthorizationError
.
Above still doesn't work even if I add the following to blitz-server
:
SuperJSON.registerClass(AuthenticationError);
SuperJSON.registerClass(AuthorizationError);
Can I use instanceof
or do I need to do if (error.name === 'AuthenticationError)
?
What is the problem?
Error: Bad request (400) error is thrown when query is set to be authorized.
I have created a simple query on a new project to return an empty array and used it on the index page's
UserInfo
component.When resolver.authorize() is commented out, I can successfully use the query in component
const [users] = useQuery(getUsers, {})
and it returns an empty array with no issues. But when I uncommentresolver.authorize()
, a400: Bad request
error is shown. By default, blitz creates aRootErrorFallback
component to be used inErrorBoundary
component as fallback.RootErrorFallback
component checks for different types of errors:For some reason, the
AuthenticationError
is skipped and the default/fallback else statement is returning theErrorComponent
.On the server-side logs, I can see the correct issue (
[AuthenticationError: You must be logged in to access this] {statusCode: 401}
) being logged, but on the client side it's just anUncaught Error: Bad Request
errorPaste all your error logs here:
Browser console:
Paste all relevant code snippets here:
What are detailed steps to reproduce this?
src/users/queries/getUsers.ts
UserInfo
component viauseQuery
from@blitzjs/rpc
blitz dev
), go to localhost, create a user/login - everything should workresolver.authorize(),
orctx.session.$authorize();
in query fileErrorComponent
will be shown instead ofError: You are not authenticated
Run
blitz -v
and paste the output here:Please include below any other applicable logs and screenshots that show your problem: