-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add login as a customer (#1749)
* feat: add login as a customer * feat: ude defaultHeaders
- Loading branch information
1 parent
c8648bd
commit 31f4a1d
Showing
4 changed files
with
45 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
templates/vue-demo-store/server/routes/account/login/imitate-customer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters