Skip to content

Commit

Permalink
redux-oidc - add more fields to User type (flow-typed#1531)
Browse files Browse the repository at this point in the history
* Add more fields to the User type based on the typescript definition
in  oidc-client-js

* trivial change to trigger travis build
  • Loading branch information
forticulous authored and gantoine committed Nov 15, 2017
1 parent 65d85ac commit 3950639
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@ declare module "redux-oidc" {
signoutRedirect: () => Promise<*>
};
declare type User<P> = {
expired: ?boolean,
id_token: string,
access_token: string,
token_type: string,
scope: string,
expires_at: number,
+expires_in: ?boolean,
+expired: ?boolean,
+scopes: Array<string>,
profile: P
};
declare type UserManagerSettings = {|
Expand Down
17 changes: 10 additions & 7 deletions definitions/npm/redux-oidc_v3.x.x/flow_v0.55.x-/test_redux-oidc.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// @flow

"use strict";
const React = require("react");
const reduxOidc = require("redux-oidc");
import type { OidcReducerState } from "redux-oidc";
import React from "react";
import reduxOidc from "redux-oidc";
// $ExpectError: flow-typed doesn't support pulling in _other_ modules yet?
const redux = require("redux");
// This was also attempted, but still no joy.
Expand Down Expand Up @@ -31,14 +32,16 @@ const userManager = reduxOidc.createUserManager(userManagerConfig);
userManager.signinRedirect();
userManager.signoutRedirect();

// The reducer has a user
const user = reduxOidc.reducer.user;
// The reducer state can have a nullable user
const state: OidcReducerState = {
user: null
};

// $ExpectError: The user could be null/undefined.
console.log(user.expired);
console.log(state.user.expired);

if (user) {
console.log(user.expired);
if (state.user) {
console.log(state.user.expired);
}

type Action = {
Expand Down

0 comments on commit 3950639

Please sign in to comment.