Error 400 "ClientResponseError 400: Failed to authenticate." but still works - Next.JS
See original GitHub issueIssue:
When hardcoding the e-mail and password for authentication it works without error. But when using enviroment variables it throws an error but is still able to fetch the data.
Provided information:
Marked in red is the wanted results:
Thus it works, but it still throws an error. O.o
code:
...
const client = new PocketBase('https://example.com');
const adminAuthData = await client.admins.authViaEmail(process.env.USERNAME, process.env.PASSWORD);
console.log(adminAuthData);
const resultList = await client.records.getList('forums', 1, 50, {
filter: 'created >= "2022-01-01 00:00:00"',
});
...
<div>
{resultList.items.map((item, i) => (
<div key={i}>
// Show all things which you want
<br/>
{i}
<br/>
{item.title}
<br/>
{i}
<br/>
{item.description}
</div>
))
}
</div>
Temporary solution idea i tried:
catching the error and ignoring it, but this could lead to a later issue where authentication actually does not work and I would not get the necessary error.
Result of temporary fix idea:
Yet this just shoves the const variable out of scope and nothing works
As it is a promise i made it ignore the error with:
const adminAuthData = await client.admins.authViaEmail(process.env.USERNAME, process.env.PASSWORD).catch((error) =>{});
I do not like this temprorary solution because of the mentioned probable issue later on.
Issue Analytics
- State:
- Created a year ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
"Failed to authenticate." Error while trying to use "client.users ...
Hi guys, I am currently using nextjs and react with pocketbase and when I try to authenticate via OAuth2, I get a code...
Read more >NextJS - getServerSideProps - Error 400 - Bad Request
It brings me the information when I do the fetch using the same parameters in React, however with Next JS it returns 400...
Read more >Why can't I access res.status(400) in the response variable?
Logging error.message returns "Request failed with status code 400"; any way to access the custom message within the JSON? Authentication ...
Read more >Errors - NextAuth.js
This occurs when there was an error in the POST request to the OAuth provider and we were not able to retrieve the...
Read more >Getting 400 error message when adding new record using ...
I was able to figure it out, I need to put the text value in single quotes 'RatingBU' and then just past the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@PeterAlfonsLoch The above code will execute twice - once in your node-server and second time in the browser (to verify add a
console.log('hello')
and open the browser console).You have to wrap it in a server-only handler.
I’ll close the issue because this is not related to the SDK, but let me know if you are still having difficulties making it work and I’ll review it in more details later this evening.
You are right.
In my eagerness to get to use pocketbase I did not correctly use my brain. I am sorry to have wasted your time.