mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-04 14:57:10 +00:00
Merge pull request #15097 from LKay/lkay/redux-auth-wrapper
Add definitions for redux-auth-wrapper
This commit is contained in:
Vendored
+33
@@ -0,0 +1,33 @@
|
||||
// Type definitions for redux-auth-wrapper 1.0
|
||||
// Project: https://github.com/mjrussell/redux-auth-wrapper
|
||||
// Definitions by: Karol Janyst <https://github.com/LKay>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.1
|
||||
|
||||
import { ComponentClass, StatelessComponent, ReactType } from "react";
|
||||
import { Action } from "redux";
|
||||
import { Location } from "history";
|
||||
|
||||
type ComponentConstructor<P> = ComponentClass<P> | StatelessComponent<P>;
|
||||
|
||||
interface InjectedProps<AuthData> {
|
||||
authData?: AuthData;
|
||||
}
|
||||
|
||||
export interface AuthWrapperConfig<State, Props, AuthData> {
|
||||
allowRedirectBack?: boolean | ((location: Location, redirectPath: string) => boolean);
|
||||
authenticatingSelector?: (state: State, ownProps?: Props) => boolean;
|
||||
authSelector: (state: State, ownProps?: Props) => AuthData;
|
||||
FailureComponent?: ReactType;
|
||||
failureRedirectPath?: string | ((state: State, ownProps?: Props) => string);
|
||||
LoadingComponent?: ReactType;
|
||||
redirectQueryParamName?: string;
|
||||
wrapperDisplayName?: string;
|
||||
predicate?: (authData: AuthData) => boolean;
|
||||
propMapper?: (ownProps: Props) => InjectedProps<AuthData> & Props;
|
||||
redirectAction?: (...args: any[]) => Action;
|
||||
}
|
||||
|
||||
type AuthDecorator<Props> = (component: ComponentConstructor<Props>) => ComponentClass<Props>;
|
||||
|
||||
export function UserAuthWrapper<State, Props, AuthData>(config: AuthWrapperConfig<State, Props, AuthData>): AuthDecorator<Props>;
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"redux": "^3.6.0"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
import * as React from "react";
|
||||
import { StatelessComponent } from "react";
|
||||
import { UserAuthWrapper } from "redux-auth-wrapper";
|
||||
|
||||
const Auth = UserAuthWrapper<any, any, any>({
|
||||
allowRedirectBack: true,
|
||||
authenticatingSelector(state: any) {
|
||||
return state.auth.loading
|
||||
},
|
||||
authSelector(state: any) {
|
||||
return state.auth
|
||||
},
|
||||
FailureComponent: () => (<div />),
|
||||
failureRedirectPath: "/401",
|
||||
LoadingComponent: () => (<div />),
|
||||
redirectAction: () => ({ type : "redirect" }),
|
||||
redirectQueryParamName: "next",
|
||||
predicate(authData: any) {
|
||||
return authData.authorized
|
||||
},
|
||||
wrapperDisplayName: "TestAuth"
|
||||
});
|
||||
|
||||
export const TestAuthComponent: StatelessComponent<any> = () => {
|
||||
return (<div />);
|
||||
};
|
||||
|
||||
const TestAuth = Auth(TestAuthComponent);
|
||||
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6",
|
||||
"dom"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": ["../"],
|
||||
"paths": {
|
||||
"history": ["history/v3"],
|
||||
"history/*": ["history/v3/*"]
|
||||
},
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"jsx": "react"
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"redux-auth-wrapper-tests.tsx"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "../tslint.json" }
|
||||
Reference in New Issue
Block a user