diff --git a/apps/api/src/lib/drizzle-auth-storage.ts b/apps/api/src/lib/drizzle-auth-storage.ts index d2c0510f..f129faf6 100644 --- a/apps/api/src/lib/drizzle-auth-storage.ts +++ b/apps/api/src/lib/drizzle-auth-storage.ts @@ -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 { diff --git a/apps/api/src/lib/storage.ts b/apps/api/src/lib/storage.ts new file mode 100644 index 00000000..33d59d46 --- /dev/null +++ b/apps/api/src/lib/storage.ts @@ -0,0 +1,46 @@ +export interface StorageAdapter { + get(key: string[]): Promise | undefined> + remove(key: string[]): Promise + set(key: string[], value: any, expiry?: Date): Promise + 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(adapter: StorageAdapter, key: string[]) { + return adapter.get(encode(key)) as Promise + } + + 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( + adapter: StorageAdapter, + key: string[] + ): AsyncIterable<[string[], T]> { + return adapter.scan(encode(key)) + } +} diff --git a/apps/web/src/app/login/page.tsx b/apps/web/src/app/login/page.tsx index c1bd7418..847c92d6 100644 --- a/apps/web/src/app/login/page.tsx +++ b/apps/web/src/app/login/page.tsx @@ -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(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} diff --git a/apps/web/src/app/signup/page.tsx b/apps/web/src/app/signup/page.tsx index 5a97acdc..5363a8f7 100644 --- a/apps/web/src/app/signup/page.tsx +++ b/apps/web/src/app/signup/page.tsx @@ -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(undefined) +export default function SignupPage() { + // const [error] = useState(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} diff --git a/packages/api-client/src/auth-client.ts b/packages/api-client/src/auth-client.ts index 2f424df0..7daad114 100644 --- a/packages/api-client/src/auth-client.ts +++ b/packages/api-client/src/auth-client.ts @@ -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) { diff --git a/packages/api-client/src/errors.ts b/packages/api-client/src/errors.ts index d2849f4e..9c7e82c5 100644 --- a/packages/api-client/src/errors.ts +++ b/packages/api-client/src/errors.ts @@ -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