Something went wrong. Try again.
Your thinking partner.
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859import { AuthRequest, CodeChallengeMethod, makeRedirectUri, ResponseType,} from "expo-auth-session";import * as WebBrowser from "expo-web-browser";
import { exchangeAuthorizationCode, getOAuthClientId, LETTA_OAUTH_BASE_URL, type OAuthCredential,} from "./oauthTokens";import { authorizationCodeFromResult } from "./oauthResult";
export { OAuthCancelledError } from "./oauthResult";
WebBrowser.maybeCompleteAuthSession();
const discovery = { authorizationEndpoint: `${LETTA_OAUTH_BASE_URL}/oauth/authorize`,};
export function getOAuthRedirectUri(): string { return makeRedirectUri({ native: "letta-mobile://oauth/callback", scheme: "letta-mobile", path: "oauth/callback", });}
export async function signInWithLetta(): Promise<OAuthCredential> { const clientId = getOAuthClientId(); if (!clientId) { throw new Error("OAuth is not configured in this build. Use an API key for now."); }
const redirectUri = getOAuthRedirectUri(); const request = new AuthRequest({ clientId, redirectUri, responseType: ResponseType.Code, usePKCE: true, codeChallengeMethod: CodeChallengeMethod.S256, }); const result = await request.promptAsync(discovery); const code = authorizationCodeFromResult(result); if (!request.codeVerifier) { throw new Error("Letta Cloud did not return the required sign-in details."); } return exchangeAuthorizationCode({ clientId, code, codeVerifier: request.codeVerifier, redirectUri, });}