kopia lustrzana https://github.com/transitive-bullshit/chatgpt-api
fix: remove last references to openauth
rodzic
8d6914f0fe
commit
31da5781bf
|
@ -1,10 +1,5 @@
|
||||||
import {
|
|
||||||
joinKey,
|
|
||||||
splitKey,
|
|
||||||
type StorageAdapter
|
|
||||||
} from '@agentic/openauth/storage/storage'
|
|
||||||
|
|
||||||
import { and, db, eq, gt, isNull, like, or, schema } from '@/db'
|
import { and, db, eq, gt, isNull, like, or, schema } from '@/db'
|
||||||
|
import { joinKey, splitKey, type StorageAdapter } from '@/lib/storage'
|
||||||
|
|
||||||
export function DrizzleAuthStorage(): StorageAdapter {
|
export function DrizzleAuthStorage(): StorageAdapter {
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -0,0 +1,46 @@
|
||||||
|
export interface StorageAdapter {
|
||||||
|
get(key: string[]): Promise<Record<string, any> | undefined>
|
||||||
|
remove(key: string[]): Promise<void>
|
||||||
|
set(key: string[], value: any, expiry?: Date): Promise<void>
|
||||||
|
scan(prefix: string[]): AsyncIterable<[string[], any]>
|
||||||
|
}
|
||||||
|
|
||||||
|
const SEPERATOR = String.fromCodePoint(0x1f)
|
||||||
|
|
||||||
|
export function joinKey(key: string[]) {
|
||||||
|
return key.join(SEPERATOR)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function splitKey(key: string) {
|
||||||
|
return key.split(SEPERATOR)
|
||||||
|
}
|
||||||
|
|
||||||
|
export namespace Storage {
|
||||||
|
function encode(key: string[]) {
|
||||||
|
return key.map((k) => k.replaceAll(SEPERATOR, ''))
|
||||||
|
}
|
||||||
|
export function get<T>(adapter: StorageAdapter, key: string[]) {
|
||||||
|
return adapter.get(encode(key)) as Promise<T | null>
|
||||||
|
}
|
||||||
|
|
||||||
|
export function set(
|
||||||
|
adapter: StorageAdapter,
|
||||||
|
key: string[],
|
||||||
|
value: any,
|
||||||
|
ttl?: number
|
||||||
|
) {
|
||||||
|
const expiry = ttl ? new Date(Date.now() + ttl * 1000) : undefined
|
||||||
|
return adapter.set(encode(key), value, expiry)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function remove(adapter: StorageAdapter, key: string[]) {
|
||||||
|
return adapter.remove(encode(key))
|
||||||
|
}
|
||||||
|
|
||||||
|
export function scan<T>(
|
||||||
|
adapter: StorageAdapter,
|
||||||
|
key: string[]
|
||||||
|
): AsyncIterable<[string[], T]> {
|
||||||
|
return adapter.scan(encode(key))
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,11 +1,10 @@
|
||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import type { PasswordLoginError } from '@agentic/openauth/provider/password'
|
|
||||||
import { isValidEmail, isValidPassword } from '@agentic/platform-validators'
|
import { isValidEmail, isValidPassword } from '@agentic/platform-validators'
|
||||||
import { useForm } from '@tanstack/react-form'
|
import { useForm } from '@tanstack/react-form'
|
||||||
import { Loader2Icon } from 'lucide-react'
|
import { Loader2Icon } from 'lucide-react'
|
||||||
import { redirect, RedirectType } from 'next/navigation'
|
import { redirect, RedirectType } from 'next/navigation'
|
||||||
import { useCallback, useState } from 'react'
|
import { useCallback } from 'react'
|
||||||
import { z } from 'zod'
|
import { z } from 'zod'
|
||||||
|
|
||||||
import { useUnauthenticatedAgentic } from '@/components/agentic-provider'
|
import { useUnauthenticatedAgentic } from '@/components/agentic-provider'
|
||||||
|
@ -17,7 +16,6 @@ import { toastError } from '@/lib/notifications'
|
||||||
import { cn } from '@/lib/utils'
|
import { cn } from '@/lib/utils'
|
||||||
|
|
||||||
export default function LoginPage() {
|
export default function LoginPage() {
|
||||||
const [error] = useState<PasswordLoginError | undefined>(undefined)
|
|
||||||
const ctx = useUnauthenticatedAgentic()
|
const ctx = useUnauthenticatedAgentic()
|
||||||
|
|
||||||
const form = useForm({
|
const form = useForm({
|
||||||
|
@ -91,7 +89,7 @@ export default function LoginPage() {
|
||||||
required
|
required
|
||||||
placeholder='Email'
|
placeholder='Email'
|
||||||
autoComplete='email'
|
autoComplete='email'
|
||||||
autoFocus={!error}
|
autoFocus={true}
|
||||||
value={field.state.value}
|
value={field.state.value}
|
||||||
onBlur={field.handleBlur}
|
onBlur={field.handleBlur}
|
||||||
onChange={(e: any) => field.handleChange(e.target.value)}
|
onChange={(e: any) => field.handleChange(e.target.value)}
|
||||||
|
@ -122,7 +120,7 @@ export default function LoginPage() {
|
||||||
type='password'
|
type='password'
|
||||||
required
|
required
|
||||||
placeholder='Password'
|
placeholder='Password'
|
||||||
autoFocus={error?.type === 'invalid_password'}
|
// autoFocus={error?.type === 'invalid_password'}
|
||||||
autoComplete='current-password'
|
autoComplete='current-password'
|
||||||
value={field.state.value}
|
value={field.state.value}
|
||||||
onBlur={field.handleBlur}
|
onBlur={field.handleBlur}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import type { PasswordLoginError } from '@agentic/openauth/provider/password'
|
|
||||||
import {
|
import {
|
||||||
isValidEmail,
|
isValidEmail,
|
||||||
isValidPassword,
|
isValidPassword,
|
||||||
|
@ -9,7 +8,7 @@ import {
|
||||||
import { useForm } from '@tanstack/react-form'
|
import { useForm } from '@tanstack/react-form'
|
||||||
import { Loader2Icon } from 'lucide-react'
|
import { Loader2Icon } from 'lucide-react'
|
||||||
import { redirect, RedirectType } from 'next/navigation'
|
import { redirect, RedirectType } from 'next/navigation'
|
||||||
import { useCallback, useState } from 'react'
|
import { useCallback } from 'react'
|
||||||
import { z } from 'zod'
|
import { z } from 'zod'
|
||||||
|
|
||||||
import { useUnauthenticatedAgentic } from '@/components/agentic-provider'
|
import { useUnauthenticatedAgentic } from '@/components/agentic-provider'
|
||||||
|
@ -20,8 +19,8 @@ import { GitHubIcon } from '@/icons/github'
|
||||||
import { toastError } from '@/lib/notifications'
|
import { toastError } from '@/lib/notifications'
|
||||||
import { cn } from '@/lib/utils'
|
import { cn } from '@/lib/utils'
|
||||||
|
|
||||||
export default function LoginPage() {
|
export default function SignupPage() {
|
||||||
const [error] = useState<PasswordLoginError | undefined>(undefined)
|
// const [error] = useState<PasswordLoginError | undefined>(undefined)
|
||||||
const ctx = useUnauthenticatedAgentic()
|
const ctx = useUnauthenticatedAgentic()
|
||||||
|
|
||||||
const form = useForm({
|
const form = useForm({
|
||||||
|
@ -105,7 +104,7 @@ export default function LoginPage() {
|
||||||
required
|
required
|
||||||
placeholder='Email'
|
placeholder='Email'
|
||||||
autoComplete='email'
|
autoComplete='email'
|
||||||
autoFocus={!error}
|
autoFocus={true}
|
||||||
value={field.state.value}
|
value={field.state.value}
|
||||||
onBlur={field.handleBlur}
|
onBlur={field.handleBlur}
|
||||||
onChange={(e: any) => field.handleChange(e.target.value)}
|
onChange={(e: any) => field.handleChange(e.target.value)}
|
||||||
|
@ -147,7 +146,7 @@ export default function LoginPage() {
|
||||||
type='password'
|
type='password'
|
||||||
required
|
required
|
||||||
placeholder='Password'
|
placeholder='Password'
|
||||||
autoFocus={error?.type === 'invalid_password'}
|
// autoFocus={error?.type === 'invalid_password'}
|
||||||
autoComplete='new-password'
|
autoComplete='new-password'
|
||||||
value={field.state.value}
|
value={field.state.value}
|
||||||
onBlur={field.handleBlur}
|
onBlur={field.handleBlur}
|
||||||
|
|
|
@ -196,7 +196,7 @@ export interface ExchangeError {
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* ```ts
|
* ```ts
|
||||||
* import { InvalidAuthorizationCodeError } from "@agentic/openauth/error"
|
* import { InvalidAuthorizationCodeError } from "@agentic/api-client/error"
|
||||||
*
|
*
|
||||||
* console.log(err instanceof InvalidAuthorizationCodeError)
|
* console.log(err instanceof InvalidAuthorizationCodeError)
|
||||||
*```
|
*```
|
||||||
|
@ -237,7 +237,7 @@ export interface RefreshError {
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* ```ts
|
* ```ts
|
||||||
* import { InvalidRefreshTokenError } from "@agentic/openauth/error"
|
* import { InvalidRefreshTokenError } from "@agentic/api-client/error"
|
||||||
*
|
*
|
||||||
* console.log(err instanceof InvalidRefreshTokenError)
|
* console.log(err instanceof InvalidRefreshTokenError)
|
||||||
*```
|
*```
|
||||||
|
@ -312,7 +312,7 @@ export interface VerifyError {
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* ```ts
|
* ```ts
|
||||||
* import { InvalidRefreshTokenError } from "@agentic/openauth/error"
|
* import { InvalidRefreshTokenError } from "@agentic/api-client/error"
|
||||||
*
|
*
|
||||||
* console.log(err instanceof InvalidRefreshTokenError)
|
* console.log(err instanceof InvalidRefreshTokenError)
|
||||||
*```
|
*```
|
||||||
|
@ -399,7 +399,7 @@ export interface AuthClient {
|
||||||
* you can handle depending on the error.
|
* you can handle depending on the error.
|
||||||
*
|
*
|
||||||
* ```ts
|
* ```ts
|
||||||
* import { InvalidAuthorizationCodeError } from "@agentic/openauth/error"
|
* import { InvalidAuthorizationCodeError } from "@agentic/api-client/error"
|
||||||
*
|
*
|
||||||
* if (exchanged.err) {
|
* if (exchanged.err) {
|
||||||
* if (exchanged.err instanceof InvalidAuthorizationCodeError) {
|
* if (exchanged.err instanceof InvalidAuthorizationCodeError) {
|
||||||
|
@ -448,7 +448,7 @@ export interface AuthClient {
|
||||||
* Or if it fails, it returns an error that you can handle depending on the error.
|
* Or if it fails, it returns an error that you can handle depending on the error.
|
||||||
*
|
*
|
||||||
* ```ts
|
* ```ts
|
||||||
* import { InvalidRefreshTokenError } from "@agentic/openauth/error"
|
* import { InvalidRefreshTokenError } from "@agentic/api-client/error"
|
||||||
*
|
*
|
||||||
* if (next.err) {
|
* if (next.err) {
|
||||||
* if (next.err instanceof InvalidRefreshTokenError) {
|
* if (next.err instanceof InvalidRefreshTokenError) {
|
||||||
|
@ -503,7 +503,7 @@ export interface AuthClient {
|
||||||
* Or if it fails, it returns an error that you can handle depending on the error.
|
* Or if it fails, it returns an error that you can handle depending on the error.
|
||||||
*
|
*
|
||||||
* ```ts
|
* ```ts
|
||||||
* import { InvalidRefreshTokenError } from "@agentic/openauth/error"
|
* import { InvalidRefreshTokenError } from "@agentic/api-client/error"
|
||||||
*
|
*
|
||||||
* if (verified.err) {
|
* if (verified.err) {
|
||||||
* if (verified.err instanceof InvalidRefreshTokenError) {
|
* if (verified.err instanceof InvalidRefreshTokenError) {
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
* You can use these errors to check the type of error and handle it. For example.
|
* You can use these errors to check the type of error and handle it. For example.
|
||||||
*
|
*
|
||||||
* ```ts
|
* ```ts
|
||||||
* import { InvalidAuthorizationCodeError } from "@agentic/openauth/error"
|
* import { InvalidAuthorizationCodeError } from "@agentic/api-client/error"
|
||||||
*
|
*
|
||||||
* if (err instanceof InvalidAuthorizationCodeError) {
|
* if (err instanceof InvalidAuthorizationCodeError) {
|
||||||
* // handle invalid code error
|
* // handle invalid code error
|
||||||
|
|
Ładowanie…
Reference in New Issue