66 */
77import { User } from 'oidc-client' ;
88
9+ // Is redux or isn't redux, that is the question, 🎭
10+ export interface Action < T > {
11+ type : T ;
12+ }
13+ type ReadonlyAction < T > = Readonly < Action < T > > ;
14+
915export const USER = 'USER' ;
16+ export type UserAction = ReadonlyAction < typeof USER > & {
17+ user : User | null ;
18+ } ;
1019
11- export function setLoggedUser ( user : User | null ) {
20+ export function setLoggedUser ( user : User | null ) : UserAction {
1221 return { type : USER , user } ;
1322}
1423
1524export const SIGNIN_CALLBACK_ERROR = 'SIGNIN_CALLBACK_ERROR' ;
25+ export type SignInCallbackErrorAction = ReadonlyAction <
26+ typeof SIGNIN_CALLBACK_ERROR
27+ > & {
28+ signInCallbackError : Error | null ;
29+ } ;
1630
17- export function setSignInCallbackError ( signInCallbackError : string | null ) {
31+ export function setSignInCallbackError (
32+ signInCallbackError : Error | null
33+ ) : SignInCallbackErrorAction {
1834 return {
1935 type : SIGNIN_CALLBACK_ERROR ,
2036 signInCallbackError,
2137 } ;
2238}
2339
40+ export type AuthenticationRouterErrorBase < T > = {
41+ authenticationRouterError : {
42+ userName ?: string ;
43+ } & T ;
44+ } ;
45+
2446export const UNAUTHORIZED_USER_INFO = 'UNAUTHORIZED_USER_INFO' ;
47+ export type UnauthorizedUserAction = ReadonlyAction <
48+ typeof UNAUTHORIZED_USER_INFO
49+ > &
50+ AuthenticationRouterErrorBase < {
51+ unauthorizedUserInfo : string ;
52+ } > ;
2553
2654export function setUnauthorizedUserInfo (
2755 userName : string | undefined ,
2856 unauthorizedUserInfo : string
29- ) {
57+ ) : UnauthorizedUserAction {
3058 return {
3159 type : UNAUTHORIZED_USER_INFO ,
3260 authenticationRouterError : {
@@ -37,11 +65,15 @@ export function setUnauthorizedUserInfo(
3765}
3866
3967export const LOGOUT_ERROR = 'LOGOUT_ERROR' ;
68+ export type LogoutErrorAction = ReadonlyAction < typeof LOGOUT_ERROR > &
69+ AuthenticationRouterErrorBase < {
70+ logoutError : { error : Error } ;
71+ } > ;
4072
4173export function setLogoutError (
4274 userName : string | undefined ,
4375 logoutError : { error : Error }
44- ) {
76+ ) : LogoutErrorAction {
4577 return {
4678 type : LOGOUT_ERROR ,
4779 authenticationRouterError : {
@@ -52,11 +84,17 @@ export function setLogoutError(
5284}
5385
5486export const USER_VALIDATION_ERROR = 'USER_VALIDATION_ERROR' ;
87+ export type UserValidationErrorAction = ReadonlyAction <
88+ typeof USER_VALIDATION_ERROR
89+ > &
90+ AuthenticationRouterErrorBase < {
91+ userValidationError : { error : Error } ;
92+ } > ;
5593
5694export function setUserValidationError (
5795 userName : string | undefined ,
5896 userValidationError : { error : Error }
59- ) {
97+ ) : UserValidationErrorAction {
6098 return {
6199 type : USER_VALIDATION_ERROR ,
62100 authenticationRouterError : {
@@ -68,21 +106,40 @@ export function setUserValidationError(
68106
69107export const RESET_AUTHENTICATION_ROUTER_ERROR =
70108 'RESET_AUTHENTICATION_ROUTER_ERROR' ;
109+ export type AuthenticationRouterErrorAction = ReadonlyAction <
110+ typeof RESET_AUTHENTICATION_ROUTER_ERROR
111+ > & {
112+ authenticationRouterError : null ;
113+ } ;
71114
72- export function resetAuthenticationRouterError ( ) {
115+ export function resetAuthenticationRouterError ( ) : AuthenticationRouterErrorAction {
73116 return {
74117 type : RESET_AUTHENTICATION_ROUTER_ERROR ,
75118 authenticationRouterError : null ,
76119 } ;
77120}
78121
79122export const SHOW_AUTH_INFO_LOGIN = 'SHOW_AUTH_INFO_LOGIN' ;
123+ export type ShowAuthenticationRouterLoginAction = ReadonlyAction <
124+ typeof SHOW_AUTH_INFO_LOGIN
125+ > & {
126+ showAuthenticationRouterLogin : boolean ;
127+ } ;
80128
81129export function setShowAuthenticationRouterLogin (
82130 showAuthenticationRouterLogin : boolean
83- ) {
131+ ) : ShowAuthenticationRouterLoginAction {
84132 return {
85133 type : SHOW_AUTH_INFO_LOGIN ,
86134 showAuthenticationRouterLogin,
87135 } ;
88136}
137+
138+ export type AuthenticationActions =
139+ | UserAction
140+ | SignInCallbackErrorAction
141+ | UnauthorizedUserAction
142+ | LogoutErrorAction
143+ | UserValidationErrorAction
144+ | AuthenticationRouterErrorAction
145+ | ShowAuthenticationRouterLoginAction ;
0 commit comments