Back

Help with OAuth2 and Discord

  • 0
  • Self Hosted
  • Auth
Alexx
22 Jan, 2025, 20:59

Hi everyone, I've been looking for the past day for solutions to my error in my code with making Discord and Appwrite work on my NextJS project. This project is just a clicker and I'm trying to setup the OAuth so you can't just click without being signed in. I'm not sure why my code doesn't work, but here it is. Also, all of my code provided is from my page.js and that's the only page I have.

loginWithDiscord Function

TypeScript
const loginWithDiscord = async () => {
    try {
      await account.createOAuth2Session(
        OAuthProvider.Discord,
        'http://localhost:3000', // Redirect URL
        'http://localhost:3000', // Success URL
        ['identify', 'email'] // Scopes
      );
    } catch (error) {
      console.error('Error logging in with Discord:', error);
    }
  };

useEffect for fetching user + clicks

TypeScript
useEffect(() => {
    const getUser = async () => {
      try {
        const user = await account.get();
        setUser(user);
        fetchClicks();
      } catch (error) {
        console.error('Error fetching session:', error);
      }
    };

    getUser();
  }, []);

Thanks if you can!

TL;DR
Developers seeking help with setting up OAuth2 for Discord and Appwrite in their NextJS clicker project. They shared code for loginWithDiscord function and useEffect for fetching user and clicks, encountering errors. They are beginners and might be making common mistakes.
Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more