Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SyntaxError: Expected ',' or '}' after property value in JSON at position 280 (line 1 column 281) #1722

Open
kvandake opened this issue May 7, 2024 · 4 comments

Comments

@kvandake
Copy link

kvandake commented May 7, 2024

Prerequisites

Please answer the following questions for yourself before submitting an issue.

  • [ x ] This is bug in the application 🐛
  • [ x ] I am running the latest version
  • [ x ] I checked the documentation and found no answer
  • [ x ] I checked to make sure that this issue has not already been filed
  • [ x ] I'm reporting the issue to the correct repository

When user state same as we get the error
SyntaxError: Expected ',' or '}' after property value in JSON at position 280 (line 1 column 281)

{
    "user": {
        "id": "f939f2ba-6358-4c7d-9e4b-863bf2bef8a0",
        "email": "[email protected]",
        "firstName": "Test",
        "lastName": "Test",
        "role": "ADMIN",
        "middleName": "Test",
        "avatar": null,
        "agreedTermsOfUse": false,
        "fullName": "Test Test Test"
    },
    "company": {
        "id": "243fde28-75ca-49c2-91e6-70e0ad09758a",
        "name": "ООО \"Test company\"",
        "type": "GENERAL_CONSTRUCTOR",
        "phoneNumber": "+988888888888",
        "city": "City",
        "verified": false
    }
}

I think the bug in line below because userState.company.name has quotes
https://github.com/react-auth-kit/react-auth-kit/blob/v3.1.3/packages/react-auth-kit/src/RxTokenObject.ts#L508

@darkmatter18
Copy link
Member

How the cookies are set?

  1. By the server using set-cookie on the http response
  2. By react-auth-kit useSignIn hook
  3. By some other client side means

Please answer the above question, so that, I can fix your issue

@kvandake
Copy link
Author

kvandake commented May 8, 2024

 import useSignIn from 'react-auth-kit/hooks/useSignIn';

const AUTH_TYPE = 'Bearer'

interface SessionInfoDto {
  user: UserDto;
  company: CompanyDto;
}


const signIn = useSignIn();
const signInWithTokenAndSessionInfo = useCallback(
  (token: string, sessionInfo: SessionInfoDto) => {
    signIn({
      auth: {
        token: token,
        type: AUTH_TYPE
      },
      userState: sessionInfo,
    });
    setTokenToAppServicesBy(`${AUTH_TYPE} ${token}`, sessionInfo.user?.role);
    return true;
  },
  [signIn],
);

Where sessionInfo

{
    "user": {
        "id": "f939f2ba-6358-4c7d-9e4b-863bf2bef8a0",
        "email": "[email protected]",
        "firstName": "Test",
        "lastName": "Test",
        "role": "ADMIN",
        "middleName": "Test",
        "avatar": null,
        "agreedTermsOfUse": false,
        "fullName": "Test Test Test"
    },
    "company": {
        "id": "243fde28-75ca-49c2-91e6-70e0ad09758a",
        "name": "ООО \"Test company\"",
        "type": "GENERAL_CONSTRUCTOR",
        "phoneNumber": "+988888888888",
        "city": "City",
        "verified": false
    }
}

Create store parameters

createStore({
      authName: 'Test',
      authType: 'localstorage',
      cookieDomain: window.location.hostname,
      cookieSecure: window.location.protocol === 'https:',
      debug: true
    });

@darkmatter18
Copy link
Member

@kvandake Thanks for the detailed information. I'll try to reproduce the bug on my system, and try to fix the issue.

@kvandake
Copy link
Author

Hello! Has any progress?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants