-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into prod-business
- Loading branch information
Showing
105 changed files
with
360 additions
and
681 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
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
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
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
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
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
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
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
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 |
---|---|---|
@@ -1,69 +1,42 @@ | ||
import { LoginRequestBody, RefreshTokenRequestBody } from "../types/auth"; | ||
import { User, userSchema } from "../types/user"; | ||
import { | ||
EmailRequestBody, | ||
VerifyEmailRequestBody, | ||
VerifyPasswordResetTokenRequestBody, | ||
} from "../types/verification"; | ||
import { baseApi } from "./base"; | ||
import { User, userSchema } from "../types"; | ||
import { LoginResponse, OAuthCallbackRequestQueryParams } from "../types/auth"; | ||
import { baseApi, handleQueryParams } from "./base"; | ||
|
||
const AUTH_API_BASE_URL = "/auth"; | ||
const PROVIDER = "microsoftonline"; | ||
|
||
export const authApi = baseApi.injectEndpoints({ | ||
endpoints: (builder) => ({ | ||
login: builder.mutation<User, LoginRequestBody>({ | ||
query: (body) => ({ | ||
login: builder.query<LoginResponse, void>({ | ||
query: () => ({ | ||
url: `${AUTH_API_BASE_URL}/login`, | ||
method: "POST", | ||
body, | ||
method: "GET", | ||
responseHandler: 'text', | ||
}), | ||
transformResponse: (response: User) => { | ||
return userSchema.parse(response); | ||
transformResponse: async (_, meta) => { | ||
const redirectUri = meta?.response?.headers.get("Redirect") as string; | ||
const sac_session = meta?.response?.headers.get("_sac_session") as string; | ||
|
||
return { | ||
redirect_uri: redirectUri, | ||
sac_session, | ||
} | ||
}, | ||
}), | ||
logout: builder.mutation<void, void>({ | ||
logout: builder.query<void, void>({ | ||
query: () => ({ | ||
url: `${AUTH_API_BASE_URL}/logout`, | ||
method: "POST", | ||
}), | ||
}), | ||
refresh: builder.mutation<void, RefreshTokenRequestBody>({ | ||
query: (body) => ({ | ||
url: "refresh", | ||
method: "POST", | ||
body, | ||
}), | ||
}), | ||
forgotPassword: builder.mutation<void, EmailRequestBody>({ | ||
query: (body) => ({ | ||
url: `${AUTH_API_BASE_URL}/forgot-password`, | ||
method: "POST", | ||
body, | ||
}), | ||
}), | ||
verifyPasswordResetToken: builder.mutation< | ||
void, | ||
VerifyPasswordResetTokenRequestBody | ||
>({ | ||
query: (body) => ({ | ||
url: `${AUTH_API_BASE_URL}/verify-reset`, | ||
method: "POST", | ||
body, | ||
method: "GET", | ||
}), | ||
}), | ||
sendCode: builder.mutation<void, EmailRequestBody>({ | ||
query: (body) => ({ | ||
url: `${AUTH_API_BASE_URL}/send-code`, | ||
method: "POST", | ||
body, | ||
}), | ||
}), | ||
verifyEmail: builder.mutation<void, VerifyEmailRequestBody>({ | ||
query: (body) => ({ | ||
url: `${AUTH_API_BASE_URL}/verify-email`, | ||
method: "POST", | ||
body, | ||
callback: builder.query<User, OAuthCallbackRequestQueryParams>({ | ||
query: (params) => ({ | ||
url: handleQueryParams(`${AUTH_API_BASE_URL}/${PROVIDER}/callback`, params), | ||
method: "GET", | ||
}), | ||
transformResponse: (response) => { | ||
return userSchema.parse(response); | ||
} | ||
}), | ||
}), | ||
}); |
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
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
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 |
---|---|---|
@@ -1,31 +1,16 @@ | ||
import { z } from "zod"; | ||
|
||
// Schemas: | ||
export const loginRequestBodySchema = z.object({ | ||
email: z.string().email(), | ||
password: z.string().min(8), | ||
export const loginResponseSchema = z.object({ | ||
redirect_uri: z.string(), | ||
sac_session: z.string(), | ||
}); | ||
|
||
export const updatePasswordRequestBodySchema = z.object({ | ||
old_password: z.string().min(8), | ||
new_password: z.string().min(8), | ||
}); | ||
|
||
export const refreshTokenRequestBodySchema = z.object({ | ||
refresh_token: z.string(), | ||
}); | ||
|
||
export const tokensSchema = z.object({ | ||
access_token: z.string(), | ||
refresh_token: z.string(), | ||
export const oauthCallbackRequestQueryParams = z.object({ | ||
code: z.string(), | ||
session_state: z.string(), | ||
state: z.string(), | ||
}); | ||
|
||
// Types: | ||
export type LoginRequestBody = z.infer<typeof loginRequestBodySchema>; | ||
export type UpdatePasswordRequestBody = z.infer< | ||
typeof updatePasswordRequestBodySchema | ||
>; | ||
export type RefreshTokenRequestBody = z.infer< | ||
typeof refreshTokenRequestBodySchema | ||
>; | ||
export type Tokens = z.infer<typeof tokensSchema>; | ||
export type LoginResponse = z.infer<typeof loginResponseSchema>; | ||
export type OAuthCallbackRequestQueryParams = z.infer<typeof oauthCallbackRequestQueryParams>; |
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
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
Oops, something went wrong.