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 { joinKey, splitKey, type StorageAdapter } from '@/lib/storage'
|
||||
|
||||
export function DrizzleAuthStorage(): StorageAdapter {
|
||||
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'
|
||||
|
||||
import type { PasswordLoginError } from '@agentic/openauth/provider/password'
|
||||
import { isValidEmail, isValidPassword } from '@agentic/platform-validators'
|
||||
import { useForm } from '@tanstack/react-form'
|
||||
import { Loader2Icon } from 'lucide-react'
|
||||
import { redirect, RedirectType } from 'next/navigation'
|
||||
import { useCallback, useState } from 'react'
|
||||
import { useCallback } from 'react'
|
||||
import { z } from 'zod'
|
||||
|
||||
import { useUnauthenticatedAgentic } from '@/components/agentic-provider'
|
||||
|
@ -17,7 +16,6 @@ import { toastError } from '@/lib/notifications'
|
|||
import { cn } from '@/lib/utils'
|
||||
|
||||
export default function LoginPage() {
|
||||
const [error] = useState<PasswordLoginError | undefined>(undefined)
|
||||
const ctx = useUnauthenticatedAgentic()
|
||||
|
||||
const form = useForm({
|
||||
|
@ -91,7 +89,7 @@ export default function LoginPage() {
|
|||
required
|
||||
placeholder='Email'
|
||||
autoComplete='email'
|
||||
autoFocus={!error}
|
||||
autoFocus={true}
|
||||
value={field.state.value}
|
||||
onBlur={field.handleBlur}
|
||||
onChange={(e: any) => field.handleChange(e.target.value)}
|
||||
|
@ -122,7 +120,7 @@ export default function LoginPage() {
|
|||
type='password'
|
||||
required
|
||||
placeholder='Password'
|
||||
autoFocus={error?.type === 'invalid_password'}
|
||||
// autoFocus={error?.type === 'invalid_password'}
|
||||
autoComplete='current-password'
|
||||
value={field.state.value}
|
||||
onBlur={field.handleBlur}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
'use client'
|
||||
|
||||
import type { PasswordLoginError } from '@agentic/openauth/provider/password'
|
||||
import {
|
||||
isValidEmail,
|
||||
isValidPassword,
|
||||
|
@ -9,7 +8,7 @@ import {
|
|||
import { useForm } from '@tanstack/react-form'
|
||||
import { Loader2Icon } from 'lucide-react'
|
||||
import { redirect, RedirectType } from 'next/navigation'
|
||||
import { useCallback, useState } from 'react'
|
||||
import { useCallback } from 'react'
|
||||
import { z } from 'zod'
|
||||
|
||||
import { useUnauthenticatedAgentic } from '@/components/agentic-provider'
|
||||
|
@ -20,8 +19,8 @@ import { GitHubIcon } from '@/icons/github'
|
|||
import { toastError } from '@/lib/notifications'
|
||||
import { cn } from '@/lib/utils'
|
||||
|
||||
export default function LoginPage() {
|
||||
const [error] = useState<PasswordLoginError | undefined>(undefined)
|
||||
export default function SignupPage() {
|
||||
// const [error] = useState<PasswordLoginError | undefined>(undefined)
|
||||
const ctx = useUnauthenticatedAgentic()
|
||||
|
||||
const form = useForm({
|
||||
|
@ -105,7 +104,7 @@ export default function LoginPage() {
|
|||
required
|
||||
placeholder='Email'
|
||||
autoComplete='email'
|
||||
autoFocus={!error}
|
||||
autoFocus={true}
|
||||
value={field.state.value}
|
||||
onBlur={field.handleBlur}
|
||||
onChange={(e: any) => field.handleChange(e.target.value)}
|
||||
|
@ -147,7 +146,7 @@ export default function LoginPage() {
|
|||
type='password'
|
||||
required
|
||||
placeholder='Password'
|
||||
autoFocus={error?.type === 'invalid_password'}
|
||||
// autoFocus={error?.type === 'invalid_password'}
|
||||
autoComplete='new-password'
|
||||
value={field.state.value}
|
||||
onBlur={field.handleBlur}
|
||||
|
|
|
@ -196,7 +196,7 @@ export interface ExchangeError {
|
|||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { InvalidAuthorizationCodeError } from "@agentic/openauth/error"
|
||||
* import { InvalidAuthorizationCodeError } from "@agentic/api-client/error"
|
||||
*
|
||||
* console.log(err instanceof InvalidAuthorizationCodeError)
|
||||
*```
|
||||
|
@ -237,7 +237,7 @@ export interface RefreshError {
|
|||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { InvalidRefreshTokenError } from "@agentic/openauth/error"
|
||||
* import { InvalidRefreshTokenError } from "@agentic/api-client/error"
|
||||
*
|
||||
* console.log(err instanceof InvalidRefreshTokenError)
|
||||
*```
|
||||
|
@ -312,7 +312,7 @@ export interface VerifyError {
|
|||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { InvalidRefreshTokenError } from "@agentic/openauth/error"
|
||||
* import { InvalidRefreshTokenError } from "@agentic/api-client/error"
|
||||
*
|
||||
* console.log(err instanceof InvalidRefreshTokenError)
|
||||
*```
|
||||
|
@ -399,7 +399,7 @@ export interface AuthClient {
|
|||
* you can handle depending on the error.
|
||||
*
|
||||
* ```ts
|
||||
* import { InvalidAuthorizationCodeError } from "@agentic/openauth/error"
|
||||
* import { InvalidAuthorizationCodeError } from "@agentic/api-client/error"
|
||||
*
|
||||
* if (exchanged.err) {
|
||||
* 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.
|
||||
*
|
||||
* ```ts
|
||||
* import { InvalidRefreshTokenError } from "@agentic/openauth/error"
|
||||
* import { InvalidRefreshTokenError } from "@agentic/api-client/error"
|
||||
*
|
||||
* if (next.err) {
|
||||
* 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.
|
||||
*
|
||||
* ```ts
|
||||
* import { InvalidRefreshTokenError } from "@agentic/openauth/error"
|
||||
* import { InvalidRefreshTokenError } from "@agentic/api-client/error"
|
||||
*
|
||||
* if (verified.err) {
|
||||
* 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.
|
||||
*
|
||||
* ```ts
|
||||
* import { InvalidAuthorizationCodeError } from "@agentic/openauth/error"
|
||||
* import { InvalidAuthorizationCodeError } from "@agentic/api-client/error"
|
||||
*
|
||||
* if (err instanceof InvalidAuthorizationCodeError) {
|
||||
* // handle invalid code error
|
||||
|
|
Ładowanie…
Reference in New Issue