How to get only access token from data

669 Views Asked by At

I have setting up a login system and I need only the access token, when i console.log my data, i get the Refresh and Token code all at once. I want just the access token even without the quotation mark please.

this is my Login Screen:

const handleSubmit = async ({ username, password }) => {
    const result = await authApi.login(username, password);
    if (!result.ok) return setLoginFailed(true);
    setLoginFailed(false);
    console.log(result.data);

Ordinarily i get something like this : "refresh": "eyJ0eX....refreshtoken", access": "eyJ0eX...accesstoken...i4ec"

But what i need is just - eyJ0eX...accesstoken...i4ec (i.e. just the access token without the quotation marks) please

1

There are 1 best solutions below

2
On

Just a typo. Use this instead:

console.log(result.data.access);