Back

[SOLVED] infinite network requests are being made for current and account

  • 0
  • Web
Ayush
25 Jun, 2023, 08:34

current https://cloud.appwrite.io/v1/account/sessions/current

account https://cloud.appwrite.io/v1/account

TypeScript
export const client=new Client()

client.setEndpoint(process.env.REACT_APP_ENDPOINT).setProject(process.env.REACT_APP_PROJECT)

export const account=new Account(client)
export const databases=new Databases(client)
export const storage=new Storage(client)```
TL;DR
The user was experiencing an issue with infinite network requests being made for current and account. The solution was to add a dependency array to the useEffect hook. This resolved the issue. The code provided shows the usage of the `account.getSession()` and `account.get()` API calls. The issue was occurring in these API calls. The user also mentioned that there were 1572 network requests being made for current and account, with over 3000 requests in total. The code snippet provided contains imports for the Appwrite client, account, databases, and storage.
Ayush
25 Jun, 2023, 08:34

what is the issue in this ?

Ayush
25 Jun, 2023, 08:40

1572 network request

Ayush
25 Jun, 2023, 08:40

on current and account

Ayush
25 Jun, 2023, 08:42
Ayush
25 Jun, 2023, 08:42

3000+

Drake
25 Jun, 2023, 14:31

That's the account.getSession() and account.get() API calls. Where are you calling those in your code?

Ayush
25 Jun, 2023, 17:18
TypeScript
        ev.preventDefault();
        if(!useremail || !password) return;

        const promise = account.createEmailSession(
            useremail,
            password
        );

        promise.then(function (response) {
          setSessionId(response['$id']);

          const _user = account.get();

          _user.then(res => {
            setCurrentUser(res);
            navigate('/', {replace: true});
          }).catch(err => {
            console.log(err,"login page");
          })
        }, function (error) {
            console.log(error,"login page function error");
        });
    }```
Ayush
25 Jun, 2023, 17:19
TypeScript
      <h1>Login</h1>
      <input className='a-input'
             type="text"
             placeholder="email"
             value={useremail}
             onChange={ev => setUseremail(ev.target.value)}/>
      <input  className='a-input'
             type="password"
             placeholder="password"
             value={password}
             onChange={ev => setPassword(ev.target.value)}/>
      <button className='a-btn'>Login</button>
    </form>```
Ayush
25 Jun, 2023, 17:38
TypeScript
        try {
            const _session=account.getSession('current')
            _session.then(res=>{
                setSessionId(res['$id'])
                const promise=account.get()
                promise.then(res=>{
                    setCurrentUser(res)
                }).catch(err=>{
                    console.log(err);
                })
            }).catch(err=>{
                console.log(err);
            })
        } catch (error) {
            console.log(error);
        }
     })```
Ayush
25 Jun, 2023, 17:38

thanks @Steven I had forgot to add the dependency array

Ayush
25 Jun, 2023, 17:38

#solved

Drake
25 Jun, 2023, 17:51

[SOLVED] infinite network requests are being made for current and account

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more