-
-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(auth): Refactor API client for otp resend
- Created new controller instance for better management of API interactions. - Added authentication controller in API client for handling OTP-related requests. - Introduced type definitions for authentication to improve type safety. - Renamed index types definition for consistency.
- Loading branch information
1 parent
f76ef3b
commit 61c25dd
Showing
6 changed files
with
82 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { AuthController } from '@keyshade/api-client' | ||
|
||
export default class ControllerInstance { | ||
private static instance: ControllerInstance | null | ||
|
||
private _authController: AuthController | null = null | ||
|
||
get authController(): AuthController { | ||
if (!this._authController) { | ||
throw new Error('ControllerInstance not initialized') | ||
} | ||
return this._authController | ||
} | ||
|
||
static initialize(baseUrl: string): void { | ||
if (!ControllerInstance.instance) { | ||
const instance = new ControllerInstance() | ||
|
||
instance._authController = new AuthController(baseUrl) | ||
|
||
ControllerInstance.instance = instance | ||
} | ||
} | ||
|
||
static getInstance(): ControllerInstance { | ||
if (!ControllerInstance.instance) { | ||
throw new Error('ControllerInstance not initialized') | ||
} | ||
return ControllerInstance.instance | ||
} | ||
} |
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,26 @@ | ||
import { | ||
ResendOTPResponse, | ||
ResendOTPRequest | ||
} from '@api-client/types/auth.types' | ||
import { APIClient } from '@api-client/core/client' | ||
import { parseResponse } from '@api-client/core/response-parser' | ||
import { ClientResponse } from '@api-client/types/index.types' | ||
export default class AuthController { | ||
private apiClient: APIClient | ||
|
||
constructor(private readonly backendURL: string) { | ||
this.apiClient = new APIClient(this.backendURL) | ||
} | ||
|
||
async resendOTP( | ||
request: ResendOTPRequest, | ||
headers?: Record<string, string> | ||
): Promise<ClientResponse<ResendOTPResponse>> { | ||
const response = await this.apiClient.post( | ||
`/api/auth/resend-otp/${request.userEmail}`, | ||
request, | ||
headers | ||
) | ||
return await parseResponse<ResendOTPResponse>(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export interface ResendOTPRequest { | ||
userEmail: string | ||
} | ||
export interface ResendOTPResponse {} |
File renamed without changes.