# Issues with Token Retrieval in JavaScript SDK Authentication

**URL:** https://forum.pinegrow.com/t/issues-with-token-retrieval-in-javascript-sdk-authentication/8960
**Category:** Javascript
**Created:** [June 23, 2024, 7:43am UTC](https://forum.pinegrow.com/t/issues-with-token-retrieval-in-javascript-sdk-authentication/8960 "2024-06-23T07:43:24Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Zahra](https://avatars.discourse-cdn.com/v4/letter/z/aeb1de/32.png) [@Zahra](https://forum.pinegrow.com/u/Zahra)
#### Post date: [June 23, 2024, 7:43am UTC](https://forum.pinegrow.com/t/issues-with-token-retrieval-in-javascript-sdk-authentication/8960/1 "2024-06-23T07:43:24Z")

</div>

Hello,

I’m facing an issue with the Authentication in my web[](https://priceindanger.com/) app. After a user signs in, the token is sometimes not retrieved correctly from localStorage, leading to unauthorized access errors.

Here’s the problematic code, how to deal it?

// Function to handle user sign-in

async function signIn(email, password) {

try {

const user = await auth.signIn({ username: email, password: password });

console.log(‘User signed in:’, user);

// Store the token

localStorage.setItem(‘authToken’, user.token);

} catch (error) {

console.error(‘Sign-in error:’, error);

}

}

// Function to retrieve the token

function getToken() {

try {

const token = localStorage.getItem(‘authToken’);

if (!token) {

throw new Error(‘No token found’);

}

return token;

} catch (error) {

console.error(‘Token retrieval error:’, error);

}

}

---

<div class="post-metadata">

### Author: ![hasan](https://avatars.discourse-cdn.com/v4/letter/h/df705f/32.png) [@hasan](https://forum.pinegrow.com/u/hasan)
#### Post date: [June 24, 2024, 5:21am UTC](https://forum.pinegrow.com/t/issues-with-token-retrieval-in-javascript-sdk-authentication/8960/2 "2024-06-24T05:21:07Z")

</div>

The question is not related with pinegrow

The **Pinegrow Community Forum** is the best place to seek, find and/or provide Help and Support about Pinegrow Web Editor.
