githubnext.jsoauth-2.0appwrite

Argument of type "github" is not assignable to parameter of type 'OAuthProvider' in Appwrite



import { account } from "@/appwrite/config"
import { Button } from "./ui/button"
import { Github } from 'lucide-react'

export default function LoginButton() {
  async function handleLogin() {
    account.createOAuth2Session(
        'github',
        'http://localhost:3000/',
        'http://localhost:3000/'
    )
  }

  return (
    <Button onClick={handleLogin} className="w-full flex items-center justify-center bg-secondary text-secondary-foreground hover:bg-secondary/90 transition-colors">
      <Github className="mr-2 h-4 w-4" />
      Login with GitHub
    </Button>
  )
}

trying to use github as provider but it shows error that "github" is not assignable to parameter of type 'OAuthProvider' in Appwrite How can to use github as a provider


Solution

  • As the AppWrite docs themselves show, your first parameter in your call to createOAuth2Session should be OAuthProvider.Github:

    import { OAuthProvider } from 'appwrite';
    // ..
    
    export default function LoginButton() {
      async function handleLogin() {
        account.createOAuth2Session(
            OAuthProvider.Github,
            'http://localhost:3000/',
            'http://localhost:3000/'
        )
      }
    
      // ...
    }
    

    It's not at all clear from where you got the idea that 'github' would be a valid parameter here.