feat(sdk): Replace region calls with the SDK in admin, apply typings … (#7371)

This commit is contained in:
Stevche Radevski
2024-05-20 14:47:31 +00:00
committed by GitHub
parent 521b4e7926
commit 025536e2a5
30 changed files with 315 additions and 185 deletions
+11 -6
View File
@@ -10,10 +10,13 @@ export class Auth {
this.config = config
}
login = async (payload: { email: string; password: string }) => {
// TODO: It is a bit strange to eg. require to pass `scope` in `login`, it might be better for us to have auth methods in both `admin` and `store` classes instead?
login = async (
scope: "admin" | "store",
method: "emailpass",
payload: { email: string; password: string }
) => {
const { token } = await this.client.fetch<{ token: string }>(
"/auth/admin/emailpass",
`/auth/${scope}/${method}`,
{
method: "POST",
body: payload,
@@ -32,9 +35,11 @@ export class Auth {
}
logout = async () => {
await this.client.fetch("/auth/session", {
method: "DELETE",
})
if (this.config?.auth?.type === "session") {
await this.client.fetch("/auth/session", {
method: "DELETE",
})
}
this.client.clearToken()
}