question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error 400 "ClientResponseError 400: Failed to authenticate." but still works - Next.JS

See original GitHub issue

Issue:

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: Bildschirm­foto 2022-11-02 um 14 06 04 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:closed
  • Created a year ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ganigeorgievcommented, Nov 2, 2022

@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.

0reactions
PeterAlfonsLochcommented, Nov 3, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found