You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在Next.js中调用Supabase signUp函数时提示‘Anonymous sign-ins are disabled’如何解决?

问题描述

在Next.js中使用Supabase实现注册功能时,调用signUp函数收到错误提示:

Anonymous sign-ins are disabled

相关代码如下:

actions.ts

'use server';

import { revalidatePath } from 'next/cache';
import { redirect } from 'next/navigation';

import { createClient } from '@/app/supabase/server';

export async function signup(formData: FormData) {
  const supabase = createClient();

  // type-casting here for convenience
  // in practice, you should validate your inputs
  const data = {
    email: formData.get('email') as string,
    password: formData.get('password') as string,
  };

  const { error } = await supabase.auth.signUp(data);

  if (error) {
    console.log(error.message);
    redirect('/error');
  }

  revalidatePath('/', 'layout')
  redirect('/home');
}

page.tsx

import Link from 'next/link';

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 { signup } from './actions';

export default async function Register() {
  return (
    <div className="flex flex-1 items-center justify-center min-h-screen">
      <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>
            <div className="grid gap-4">
              <div className="grid gap-2">
                <Label htmlFor="email">Email</Label>
                <Input
                  id="email"
                  type="email"
                  placeholder="email@example.com"
                  required
                />
              </div>
              <div className="grid gap-2">
                <Label htmlFor="password">Password</Label>
                <Input
                  id="password"
                  placeholder="Must be at least 6 characters"
                  type="password"
                  required
                />
              </div>
              <Button formAction={signup} type="submit" className="w-full">
                Create an account
              </Button>
              <Button variant="outline">
                <span>Sign Up with GitHub</span>
              </Button>
              <Button variant="outline">
                <span>Sign Up with Google</span>
              </Button>
            </div>
          </form>
          <div className="mt-4 text-center text-sm">
            Already have an account?{' '}
            <Link href="/login" className="underline">
              Sign in
            </Link>
          </div>
        </CardContent>
      </Card>
    </div>
  );
}

参考了Supabase官方的Next.js服务端认证文档。

解决方法

这个错误的核心原因是Supabase项目中未启用邮箱/密码认证服务,导致系统默认尝试匿名登录而触发限制。按以下步骤开启:

  1. 登录Supabase控制台,进入目标项目
  2. 在左侧导航栏选择「Authentication」→「Providers」
  3. 找到「Email」选项卡,勾选「Enable email provider」
  4. 保存设置后重新测试注册功能

额外检查点:

  • 确保@/app/supabase/server.ts中的createClient配置正确,使用了项目的URL和服务端密钥
  • 表单输入的邮箱格式正确,密码长度符合Supabase默认的最小6位要求

内容的提问来源于stack exchange,提问作者idevelopapps

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.25 16:05:16