Click here to Skip to main content
15,885,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have been trying to add Google's Oauth2 to my ReactJs app

but I get 2 errors which Are probably coming from a syntax error

this is the part of the code where I get the errors

import React from 'react'
import { useGoogleLogin } from 'react-use-googlelogin'

const GoogleAuthContext = React.createContext()

export const GoogleAuthProvider = ({ children }) => {
  const googleAuth = useGoogleLogin({
    clientId: process.env.Google_Client_ID,
  })

  return (
    <GoogleAuthContext.Provider value={googleAuth}>
      {children}
    </GoogleAuthContext.Provider>
  )
}

export const useGoogleAuth = () => React.useContext(GoogleAuthContext);


when I do replace Google_Client_ID with my own ID I get these errors

Quote:
Unexpected token, expected "," (8:25)


and the Second one is

Quote:
Unexpected token, expected ":" (8:37)


What I have tried:

this is how I use the client ID

 const googleAuth = useGoogleLogin({
clientId:process.env.658977310896-knrl3gka66fldh83dao2rhgbblmd4un9.apps.googleusercontent.com,
  })



THANK YOU for taking the time to Read through my question
Posted
Comments
Richard MacCutchan 27-Jun-21 6:36am    
Whatever actual data is being processed the error messages are telling you which character positions are incorrect. Check the content to see why.
Richard Deeming 28-Jun-21 4:31am    
658977310896-knrl3gka66fldh83dao2rhgbblmd4un9 is not a valid Javascript identifier. Your code is interpreted as a subtraction operation:
(process.env.658977310896) - (knrl3gka66fldh83dao2rhgbblmd4un9.apps.googleusercontent.com)

I suspect you meant to use:
clientId:process.env["658977310896-knrl3gka66fldh83dao2rhgbblmd4un9.apps.googleusercontent.com"],

But without seeing how the env is set up, that's just a guess.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900