Back

i need help: general_unauthorized_scope

  • 1
  • Auth
  • Web
kmΟShα
13 Oct, 2024, 01:16

any one can help me?

TL;DR
The developers are facing an issue with 'general_unauthorized_scope' in their code related to authentication. The problem seems to stem from unauthorized access. Solution: Make sure that proper scopes are set for the OAuthProvider in the code for successful authentication.
kmΟShα
13 Oct, 2024, 01:17

this is my code:

TypeScript
// lib/auth.ts
"use server";

import {
  API_ENDPOINT,
  API_KEY,
  PROJECT_ID,
  SESSION_COOKIE,
} from "@/config/appwrite";
import { Account, Client, OAuthProvider } from "node-appwrite";
import { cookies, headers } from "next/headers";

let appwriteClient = new Client()
  .setEndpoint(API_ENDPOINT)
  .setProject(PROJECT_ID)
  .setKey(API_KEY);

let account = new Account(appwriteClient);

export async function getSession() {
  const cookieStore = cookies();
  const sessionId = cookieStore.get(SESSION_COOKIE)?.value;

  if (!sessionId) {
    return null;
  }

  try {
    const session = await account.getSession(sessionId);
    return session;
  } catch (error) {
    console.error("Failed to get session:", error);
    return null;
  }
}

export async function signIn(provider: "google") {
  const origin = headers().get("origin") || "";

  const success = `${origin}/api/auth/callback/${provider}`;
  const failure = `${origin}/auth/error`;

  const url = await account.createOAuth2Token(
    OAuthProvider.Google,
    success,
    failure
  );
  return { url };
}
kmΟShα
13 Oct, 2024, 01:23

@Steven sorry for ping.. but did you have any solve?

kmΟShα
13 Oct, 2024, 01:24

i need help: general_unauthorized_scope

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