Skip to content

Commit

Permalink
feat: add login as a customer (#1749)
Browse files Browse the repository at this point in the history
* feat: add login as a customer

* feat: ude defaultHeaders
  • Loading branch information
mdanilowicz authored Mar 3, 2025
1 parent c8648bd commit 31f4a1d
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/tricky-poets-strive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"vue-demo-store": minor
---

Add server routing to handle login as a customer option
2 changes: 1 addition & 1 deletion templates/vue-demo-store/server/apiBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ const apiClient = createAPIClient<operations>({
baseURL: shopwareEndpoint,
});

export default apiClient;
export { shopwareEndpoint, shopwareAccessToken, apiClient };
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { createAPIClient } from "@shopware/api-client";
import type { operations } from "#shopware";
import { shopwareAccessToken, shopwareEndpoint } from "../../../apiBuilder";

export default defineEventHandler(async (event) => {
const body = await readBody(event);
if (!body.customerId || !body.token || !body.userId) {
await sendRedirect(event, "/", 400);
return;
}
const apiClient = createAPIClient<operations>({
accessToken: shopwareAccessToken,
baseURL: shopwareEndpoint,
});

await apiClient.invoke(
"imitateCustomerLogin post /account/login/imitate-customer",
{
body: {
customerId: body.customerId,
token: body.token,
userId: body.userId,
},
},
);

if (!apiClient.defaultHeaders["sw-context-token"]) {
await sendRedirect(event, "/", 400);
return;
}
setCookie(
event,
"sw-context-token",
apiClient.defaultHeaders["sw-context-token"],
);

await sendRedirect(event, "/account", 200);
});
2 changes: 1 addition & 1 deletion templates/vue-demo-store/server/routes/sitemap.xml.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Readable } from "node:stream";
import getURL from "requrl";
import { SitemapIndexStream, streamToPromise } from "sitemap";
import apiClient from "../apiBuilder";
import { apiClient } from "../apiBuilder";

type Sitemap = {
url: string;
Expand Down

0 comments on commit 31f4a1d

Please sign in to comment.