Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added the ability to connect request interceptors #25

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Volodomor
Copy link

I want to add the ability to connect request interceptors that can perform certain actions before performing standard request processing.

Now, using this mechanism, we plan to connect handlers for different types of authentication, which, if there are certain cookies in the response, will trigger actions in the background to update the user's authorization cookies.

@Volodomor Volodomor force-pushed the requests-interceptors-mechanism branch from 37a9001 to d445c77 Compare January 30, 2025 09:16
@Volodomor Volodomor force-pushed the requests-interceptors-mechanism branch from d445c77 to 6551b53 Compare January 30, 2025 11:38
@resure resure requested a review from SeqviriouM February 4, 2025 08:49
lib/index.ts Outdated
@@ -41,6 +50,7 @@ export interface SdkConfig {
service?: string,
action?: string,
) => SdkActionFunc<TRequestData, TResponseData>;
queriesInterceptors?: ScopeServiceQueryInterceptors[];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be call this option as axiosInterceptors? The same naming used in gateway

@@ -23,6 +26,12 @@ export interface SdkActionFunc<TRequestData, TResponseData> {
(data: TRequestData, options?: SdkActionOptions): CancellablePromise<TResponseData>;
}

export type ScopeServiceQueryInterceptors = {
scope?: string;
service: string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I get correctly we can set up interceptors per service? And to update cookie we will set interceptor for session-service

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, interceptors are attached to the service, but this does not specifically mean session-service, but the service in the general form in which it is set for gateway actions, for example, "Backend". That is, here we do not just list all possible authentication methods, but for each service we hang the necessary interceptors module, depending on which authentication is used to access the api of this service. For example, we know that "passport" is used for the "Backend" service, and here we will connect to SDK the appropriate interceptors module for the passport. For some other service, for example, "Tracker", "passport" can also be used, and we will attach the same interceptors module to this service. And in the service, for example, "Cloud", we use "iam". Then we will hang a interceptors module on it that can update cookies during iam authentication. If we have such a interceptors module.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants