feat(ecommerce): login con Google para clientes
Implementa el flujo completo de OAuth social de Medusa para el storefront: boton "Continuar con Google" en account-dialog, ruta proxy que arranca el flujo (GET /api/customer/google/start) y pagina de callback en /auth/google/callback (coincide con GOOGLE_CALLBACK_URL del secret) que resuelve el code/state contra el backend, decodifica el JWT para distinguir cliente nuevo vs existente, crea el customer si hace falta y refresca el token a sesion final -- mismo patron de store/customer-store.ts que login/register por email. Flujo verificado en vivo contra el backend ya desplegado (GET /auth/customer/google, /auth/customer/google/callback con state invalido, /auth/token/refresh con bearer invalido) antes de escribir el codigo, no solo contra la documentacion.
This commit is contained in:
1 parent
da10a4b688
commit
77389aea19
7 files changed
+163
No files matched your search
@@ -23,6 +23,7 @@ interface CustomerState {
|
||||
setHasHydrated: (value: boolean) => void;
|
||||
register: (email: string, password: string, firstName: string, lastName: string) => Promise<boolean>;
|
||||
login: (email: string, password: string) => Promise<boolean>;
|
||||
loginWithGoogle: (code: string, state: string) => Promise<boolean>;
|
||||
logout: () => void;
|
||||
syncCustomer: () => Promise<void>;
|
||||
}
|
||||
@@ -77,6 +78,17 @@ export const useCustomerStore = create<CustomerState>()(
|
||||
return true;
|
||||
},
|
||||
|
||||
loginWithGoogle: async (code, state) => {
|
||||
set({ loading: true, error: null });
|
||||
const result = await postJson("/api/customer/google/callback", { code, state });
|
||||
if (result.error) {
|
||||
set({ loading: false, error: result.error });
|
||||
return false;
|
||||
}
|
||||
set({ loading: false, token: result.token, customer: toCustomer(result) });
|
||||
return true;
|
||||
},
|
||||
|
||||
logout: () => set({ token: null, customer: null, error: null }),
|
||||
|
||||
// El token guardado en localStorage puede llevar dias o haber sido
|
||||
|
||||
Reference in new issue
Block a user