[해결됨] Appwrite 사용자 역할 누락 또는 범위 오류 누락

Patricia Arquette
풀어 주다: 2024-10-09 10:53:02
원래의
780명이 탐색했습니다.

[Solved] Appwrite user role missing or missing scope errors

Appwrite는 애플리케이션을 빠르게 구축하려는 경우 사용할 수 있는 훌륭한 도구이지만 때로는 실망스러울 수 있는 오류가 발생할 수 있으며 저에게 이러한 오류는 항상 "사용자 역할 누락" 또는 "이 작업을 수행할 권한이 없는 사용자" 등. 비록 내가 내 앱의 모든 인스턴스에 대해 모든 작업에 대한 전체 액세스 권한을 갖고 있음에도 불구하고.

하지만 마침내 모든 문제를 해결할 수 있는 방법을 찾았습니다.(모두는 아닐 수도 있지만 그렇게 생각하고 싶습니다).

그래서 이번 디스코드 포스팅은 사실 아주 미묘하게 설명을 했네요.

중요한 점은 프로젝트에서 사용하는 방법 중 하나를 사용하여 세션이 있는지 확인하는 것입니다.

  • 익명 세션 생성
  • 이메일 비밀번호 세션 생성
  • createOAuth2Session
  • 세션 생성

이 오류가 발생한 예를 들어보겠습니다. 그러면 더 명확해질 수 있습니다.

가입 페이지가 있는데 사용자가 계정 생성 또는 가입을 클릭하자마자 확인 이메일이 실행되어야 하는데 사용자가 승인되지 않았다는 오류가 발생하고 싶습니다. 해결책은 이메일을 트리거하기 전에 세션을 생성하는 것이었습니다. 이메일을 트리거하기 전에 세션을 생성하는 방법은 다음 코드를 참조하십시오.

"use client";

import Link from "next/link";
import { FormEvent } from "react";
import { Button } from "@/components/ui/button";
import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { createAuthAccount } from "@/app/appwrite/createAuthAccount";
import { createLoginSession } from "@/app/appwrite/createLoginSession";
import { useRouter } from "next/navigation";
import { sendVerificationEmail } from "@/app/appwrite/sendVerificationEmail";

export const description =
  "A sign up form with first name, last name, email and password inside a card. There's an option to sign up with GitHub and a link to login if you already have an account";

export default function LoginForm() {
  const router = useRouter();
  const signUpFormHandler = async (event: FormEvent) => {
    event.preventDefault();
    const formData = new FormData(event.target as HTMLFormElement);
    const data = Object.fromEntries(formData.entries());
    const createdAccount = await createAuthAccount({
      email: data?.email.toString(),
      password: data?.password.toString(),
      name: data?.["full-name"].toString(),
    });
    if (createdAccount?.$id) {
      await createLoginSession({
        email: data?.email.toString(),
        password: data?.password.toString(),
      });
      await sendVerificationEmail();
    }
  };

  return (
    <Card className="mx-auto max-w-sm">
      <CardHeader>
        <CardTitle className="text-xl">Sign Up</CardTitle>
        <CardDescription>
          Enter your information to create an account
        </CardDescription>
      </CardHeader>
      <CardContent>
        <form onSubmit={signUpFormHandler} className="grid gap-4">
          <div className="grid gap-2">
            <Label htmlFor="full-name">Full name</Label>
            <Input name="full-name" id="full-name" placeholder="Max" required />
          </div>
          <div className="grid gap-2">
            <Label htmlFor="email">Email</Label>
            <Input
              id="email"
              type="email"
              placeholder="m@example.com"
              required
              name="email"
            />
          </div>
          <div className="grid gap-2">
            <Label htmlFor="password">Password</Label>
            <Input name="password" id="password" type="password" />
          </div>
          <Button type="submit" className="w-full">
            Create an account
          </Button>
        </form>
        <div className="mt-4 text-center text-sm">
          Already have an account?{" "}
          <Link href="#" className="underline">
            Sign in
          </Link>
        </div>
      </CardContent>
    </Card>
  );
}

로그인 후 복사

이것은 의도된 동작과 현재 발생한 상황, 예상되는 작업을 보여주는 예일 뿐입니다.

나처럼 Appwrite를 처음 사용하는 초보자가 이 오류에 직면할 경우를 대비해 공유하고 싶었습니다. 전체적으로 나는 범위 오류 또는 사용자 승인되지 않은 오류가 발생한 후 세션을 생성하거나 적어도 해당 메서드를 호출하기 전에 세션이 존재하는지 확인하는 거의 모든 경우에 이러한 문제가 해결되었음을 발견했습니다. 그러니 이것을 시도해보고 무슨 일이 일어나는지 알려주세요

위 내용은 [해결됨] Appwrite 사용자 역할 누락 또는 범위 오류 누락의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

원천:dev.to
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
저자별 최신 기사
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!