Skip to content

Commit

Permalink
Update optional params for signinRedirect, successCallback, and more …
Browse files Browse the repository at this point in the history
…fields to the User type. (flow-typed#1544)
  • Loading branch information
ccxiadev authored and gantoine committed Nov 17, 2017
1 parent 9accb22 commit c285974
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import type { Reducer, Store } from "redux";

declare module "redux-oidc" {
declare type UserManager = {
signinRedirect: () => Promise<*>,
signinRedirect: (data?: {
data: {
redirectUrl: string
}
}) => Promise<*>,
signoutRedirect: () => Promise<*>
};
declare type User<P> = {
Expand All @@ -14,7 +18,10 @@ declare module "redux-oidc" {
+expires_in: ?boolean,
+expired: ?boolean,
+scopes: Array<string>,
profile: P
profile: P,
state: {
redirectUrl: string
}
};
declare type UserManagerSettings = {|
client_id: string,
Expand All @@ -41,7 +48,7 @@ declare module "redux-oidc" {

declare class CallbackComponent extends React$Component<{
userManager: UserManager,
successCallback: () => mixed,
successCallback: (user?: User<*>) => mixed,
errorCallback?: () => mixed
}> {}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @flow

"use strict";
import type { OidcReducerState } from "redux-oidc";
import type { OidcReducerState, User } from "redux-oidc";
import React from "react";
import reduxOidc from "redux-oidc";
// $ExpectError: flow-typed doesn't support pulling in _other_ modules yet?
Expand Down Expand Up @@ -32,6 +32,10 @@ const userManager = reduxOidc.createUserManager(userManagerConfig);
userManager.signinRedirect();
userManager.signoutRedirect();

userManager.signinRedirect({
data: { redirectUrl: "https://www.duckduckgo.com" }
});

// The reducer state can have a nullable user
const state: OidcReducerState = {
user: null
Expand All @@ -50,6 +54,7 @@ type Action = {
type State = {
foo: string
};

// redux-oidc provides some components.
const reducer = (state: State, action: Action) => action;
const store = redux.createStore(redux.combineReducers([reducer]));
Expand All @@ -67,5 +72,22 @@ const StatelessComponent = () => {
);
};

type Props = {
redirectToLink: (user?: User<*>) => void
};

const ExampleComponent = ({ redirectToLink }: Props) => {
return (
<div>
<CallbackComponent
userManager={userManager}
successCallback={redirectToLink}
errorCallback={() => console.log("error!")}
/>
<OidcProvider store={store} userManager={userManager} />
</div>
);
};

// There's a utility function for silent renews.
reduxOidc.processSilentRenew();

0 comments on commit c285974

Please sign in to comment.