@envelop/generic-auth 4.2.3 → 4.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +6 -6
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { DefaultContext, Plugin } from '@envelop/core';
|
|
1
|
+
import { DefaultContext, Maybe, Plugin, PromiseOrValue } from '@envelop/core';
|
|
2
2
|
import { DirectiveNode, FieldNode, GraphQLError, GraphQLObjectType } from 'graphql';
|
|
3
3
|
export declare class UnauthenticatedError extends GraphQLError {
|
|
4
4
|
}
|
|
5
|
-
export declare type ResolveUserFn<UserType, ContextType = DefaultContext> = (context: ContextType) =>
|
|
5
|
+
export declare type ResolveUserFn<UserType, ContextType = DefaultContext> = (context: ContextType) => PromiseOrValue<Maybe<UserType>>;
|
|
6
6
|
export declare type ValidateUserFnParams<UserType> = {
|
|
7
7
|
/** The user object. */
|
|
8
8
|
user: UserType;
|
|
@@ -18,7 +18,7 @@ export declare type ValidateUserFnParams<UserType> = {
|
|
|
18
18
|
export declare type ValidateUserFn<UserType> = (params: ValidateUserFnParams<UserType>) => void | UnauthenticatedError;
|
|
19
19
|
export declare const DIRECTIVE_SDL = "\n directive @auth on FIELD_DEFINITION\n";
|
|
20
20
|
export declare const SKIP_AUTH_DIRECTIVE_SDL = "\n directive @skipAuth on FIELD_DEFINITION\n";
|
|
21
|
-
export declare type GenericAuthPluginOptions<UserType extends {} = {}, ContextType
|
|
21
|
+
export declare type GenericAuthPluginOptions<UserType extends {} = {}, ContextType = DefaultContext, CurrentUserKey extends string = 'currentUser'> = {
|
|
22
22
|
/**
|
|
23
23
|
* Here you can implement any custom sync/async code, and use the context built so far in Envelop and the HTTP request
|
|
24
24
|
* to find the current user.
|
|
@@ -30,7 +30,7 @@ export declare type GenericAuthPluginOptions<UserType extends {} = {}, ContextTy
|
|
|
30
30
|
* Overrides the default field name for injecting the user into the execution `context`.
|
|
31
31
|
* @default currentUser
|
|
32
32
|
*/
|
|
33
|
-
contextFieldName?:
|
|
33
|
+
contextFieldName?: CurrentUserKey;
|
|
34
34
|
} & ({
|
|
35
35
|
/**
|
|
36
36
|
* This mode offers complete protection for the entire API.
|
|
@@ -75,6 +75,6 @@ export declare type GenericAuthPluginOptions<UserType extends {} = {}, ContextTy
|
|
|
75
75
|
});
|
|
76
76
|
export declare function defaultProtectAllValidateFn<UserType>(params: ValidateUserFnParams<UserType>): void | UnauthenticatedError;
|
|
77
77
|
export declare function defaultProtectSingleValidateFn<UserType>(params: ValidateUserFnParams<UserType>): void | UnauthenticatedError;
|
|
78
|
-
export declare const useGenericAuth: <UserType extends {} = {}, ContextType
|
|
78
|
+
export declare const useGenericAuth: <UserType extends {} = {}, ContextType = DefaultContext, CurrentUserKey extends string = "currentUser">(options: GenericAuthPluginOptions<UserType, ContextType, CurrentUserKey>) => Plugin<{
|
|
79
79
|
validateUser: ValidateUserFn<UserType>;
|
|
80
|
-
}
|
|
80
|
+
} & Record<CurrentUserKey, UserType>>;
|