Back

Getting Encoding Error in the Appwrite Nextjs Integration

  • 0
  • Users
  • Accounts
  • Web
Deepanshu Goel
7 Oct, 2023, 14:29
TypeScript

// code for the appwrite config
import { Client, Account } from "appwrite";
import conf from "./config";
const client = new Client();

client.setEndpoint(conf.appwriteUrl).setProject(conf.appwriteProjectId);

const account = new Account(client);

export const sdk = {
  register: async (success, failure) => {
    // Register by creating an OAuth2 session
    account.createOAuth2Session("github", success, failure);
  },

  getAccount: async () => {
    //get account data
    return await account.get();
  },

  getSession: async () => {
    //get current session data
    return await account.getSession("current");
  },

  getGithubData: async () => {
    //get user's provider access token
    const promise = await account.getSession("current");

    const providerAccessToken = promise.providerAccessToken;
    //make a request to github api
    const response = await fetch("https://api.github.com/user", {
      headers: { Authorization: `token ${providerAccessToken}` },
    });
    return await response.json();
  },

  logout: async () => {
    // Delete the session
    await account.deleteSession("current");
  },
};
TL;DR
The user is experiencing an encoding error in the Appwrite Next.js integration. They asked for help in the support thread but then found a solution on their own. The solution was to install encoding as a dev dependency. The user also apologized for tagging someone for help. There is no further discussion or solution provided in the thread.
Deepanshu Goel
7 Oct, 2023, 14:29
TypeScript
"use client";
import React from "react";
import Image from "@/components/Image";
import Button from "@/components/Button";
import { AiFillGithub } from "react-icons/ai";
import { BsGoogle } from "react-icons/bs";
import { sdk } from "@/conf/Appwrite";

export default function Login() {
  const handleLoginGithub = () => {
    sdk.register("http://localhos:3000/home", "http://localhost:3000/login");
  };
  return (
    <div className="container h-screen w-full p-6 over">
      <div className=" flex h-full justify-between items-center">
        <div className="grid grid-cols-2 gap-10">
          <div className="flex justify-center items-center">
            <div className="flex flex-col gap-3">
              <h2 className="text-5xl font-bold">Open-SpaceLink</h2>
              <h2 className="text-2xl">
                Open Source Marketplace - Empowering Innovation
              </h2>
              <div>
                <Button
                  icon={<BsGoogle />}
                  text="Log in with Google"
                  color="secondary"
                  onClick={() => {
                    //login with google
                  }}
                />
                <Button
                  icon={<AiFillGithub />}
                  text="Log in with Github"
                  color="primary"
                  onClick={handleLoginGithub}
                />
              </div>
            </div>
          </div>
          <Image image_url="/Login_graphic.png" alt="login" />
        </div>
      </div>
    </div>
  );
}
Deepanshu Goel
7 Oct, 2023, 14:35

@Core can you please help me out?

Drake
7 Oct, 2023, 14:41

Please do not tag people or teams just because you need help as it can be very disruptive.

Deepanshu Goel
7 Oct, 2023, 14:41

Sorry for that.

Drake
7 Oct, 2023, 14:45

For now, you can install encoding as a dev dependency

Deepanshu Goel
7 Oct, 2023, 14:45

Okay sure.

Deepanshu Goel
7 Oct, 2023, 15:00

Still the same error.

Drake
7 Oct, 2023, 15:02

Or install as a regular dependency?

Deepanshu Goel
7 Oct, 2023, 15:08

Solved thanks!

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