@techsio/storefront-data
Version:
Medusa-first storefront data layer built on TanStack Query.
65 lines • 2.37 kB
TypeScript
import type Medusa from "@medusajs/js-sdk";
import type { HttpTypes } from "@medusajs/types";
import type { AuthService } from "./types";
export type MedusaAuthCredentials = {
email: string;
password: string;
};
export type MedusaRegisterData = {
email: string;
password: string;
first_name?: string;
last_name?: string;
};
export type MedusaUpdateCustomerData = Partial<{
first_name: string;
last_name: string;
phone: string;
}>;
export type MedusaRequestCustomerAccountDeactivationResult = {
customer_id: string;
sent: boolean;
};
export type MedusaConfirmCustomerAccountDeactivationInput = {
token: string;
};
export type MedusaDeactivateCustomerAccountResult = {
auth_identity_deleted: boolean;
customer_id: string;
deleted: boolean;
};
export declare class MedusaRegistrationSignInError extends Error {
readonly code = "registration_sign_in_failed";
readonly email: string;
readonly reason: unknown;
constructor(email: string, reason: unknown);
}
export type MedusaLogoutErrorContext = "logout" | "register-cleanup" | "register-signin-recovery";
export type MedusaAuthServiceConfig = {
onLogoutError?: (error: unknown, context: MedusaLogoutErrorContext) => void;
};
/**
* Creates an AuthService for Medusa SDK
*
* Includes multi-step registration flow:
* 1. Register auth identity
* 2. Login to establish customer auth state
* 3. Create customer profile
* 4. Refresh auth state so subsequent requests use a token/session that
* includes the created customer actor.
*
* @example
* ```typescript
* import { createAuthHooks } from "@techsio/storefront-data/auth/hooks"
* import { createMedusaAuthService } from "@techsio/storefront-data/auth/medusa-service"
* import { sdk } from "@/lib/medusa-client"
*
* export const authHooks = createAuthHooks({
* service: createMedusaAuthService(sdk),
* queryKeys: authQueryKeys,
* cacheConfig,
* })
* ```
*/
export declare function createMedusaAuthService(sdk: Medusa, config?: MedusaAuthServiceConfig): AuthService<HttpTypes.StoreCustomer, MedusaAuthCredentials, MedusaRegisterData, MedusaUpdateCustomerData, unknown, string, string, MedusaRequestCustomerAccountDeactivationResult, MedusaConfirmCustomerAccountDeactivationInput, MedusaDeactivateCustomerAccountResult>;
//# sourceMappingURL=medusa-service.d.ts.map