Skip to content

Error: Access token can not be extracted. Either whole 'session' must be a string (access token only) or 'getAccessToken' function should be provided #30

@RylanSchaeffer

Description

@RylanSchaeffer

Hi! I'm a novice to React and JS, and I'm trying to get around the following error: Uncaught (in promise) Error: Access token can not be extracted. Either whole 'session' must be a string (access token only) or 'getAccessToken' function should be provided.

My error occurs in the following code:

const handleSubmit = (e) => {

  e.preventDefault();

  let opts = {
    "price_id": "price_1LAHFfANX7SRTyI1CAVCDmNl",
    // TODO: Add auth token
  }

  authFetch(
    // fetch(
    `${process.env.REACT_APP_URL_BACKEND}/create-checkout-session`,
    {
      method: 'post',
      body: JSON.stringify(opts)
    })
  .then(r => {
    console.log(r.json())
    return r.json()})
  // .then(token => {
  //   if (token.access_token){
  //     // Saves token to local storage.
  //     login(token)
  //     console.log(token)
  //   }
  //   else {
  //     // TODO: Display message if invalid credentials are provided.
  //     console.log("Invalid credentials.")
  //   }
  //   console.log(token)
  // })
}

Can someone explain to me why this occurs and how to fix it?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions