Skip to content

SPA calling session/whoami: CORS problem #1217

Answered by dduzgun-security
zn8nz asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @zn8nz, I had a similar issue.
Can you try this call and see if it works for you?

const [userIdentity, setUserIdentity] = useState();

useEffect(() => {
    fetch("http://127.0.0.1:4433/sessions/whoami", {credentials: "include"})
      .then(response => response.json())
      .then(data => {
        setUserIdentity(data);
      })
}, []);

Also, be sure that the ORY cookies are still stored in the browser when calling the endpoint and that you have configured the allowed_origins field correctly in kratos.yml.

serve:
  public:
      base_url: http://127.0.0.1:4433
      cors:
        enabled: true
        allowed_origins:
          - http://127.0.0.1:3000

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@vinckr
Comment options

@zn8nz
Comment options

Answer selected by zn8nz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants