代码之家  ›  专栏  ›  技术社区  ›  MrPine

localhost:3000 api trpc authCallback

  •  0
  • MrPine  · 技术社区  · 1 年前

    我试着关注一些项目,不确定我错过了哪一部分,我试着注册帐户不工作,只继续加载设置帐户。

    我使用Kinde处理用户身份验证、授权和其他与身份相关的功能,使用prsima和带有本地数据库mysql的sycn。

    auth-callback
    
    "use client"
    
    import { useRouter, useSearchParams } from 'next/navigation'
    import { trpc } from '../\_trpc/client'
    import { Loader2 } from 'lucide-react'
    
    const Page = () =\> {
    const router = useRouter()
    
    const searchParams = useSearchParams()
    const origin = searchParams.get('origin')
    
    trpc.authCallback.useQuery(undefined, {
    onSuccess: ({ success }) =\> {
    if (success) {
    // user is synced to db
    router.push(origin ? `/${origin}` : '/dashboard')
    }
    },
    onError: (err) =\> {
    if (err.data?.code === 'UNAUTHORIZED') {
    router.push('/sign-in')
    }
    },
    retry: true,
    retryDelay: 500,
    })
    
    return (
    \<div className='w-full mt-24 flex justify-center'\>
    \<div className='flex flex-col items-center gap-2'\>
    \<Loader2 className='h-8 w-8 animate-spin text-zinc-800' /\>
    \<h3 className='font-semibold text-xl'\>
    Setting up your account...
    \</h3\>
    \<p\>You will be redirected automatically.\</p\>
    \</div\>
    \</div\>
    )
    }
    
    export default Page
    

    这是我管理同步数据库的示例。

    .env
    DATABASE_URL='mysql://username:randompassword@localhost:3306/test'
    

    mysql表显示相同的id、电子邮件和以下内容。

    generator client {
      provider = "prisma-client-js"
    }
    
    
    datasource db {
      provider     = "mysql"
      url          = env("DATABASE_URL")"
    }
    
    model User {
      id        String @id @unique //matches kinde user id
      email     String @unique
    
      stripeCustomerId       String?   @unique @map(name: "stripe_customer_id")
      stripeSubscriptionId   String?   @unique @map(name: "stripe_subscription_id")
      stripePriceId          String?   @map(name: "stripe_price_id")
      stripeCurrentPeriodEnd DateTime? @map(name: "stripe_current_period_end")
    }
    

    Tyring设置帐户出现

    enter image description here

    期望解析能够与本地数据库同步的登录或注册帐户。

    0 回复  |  直到 1 年前