use-jwt-manager
Advanced tools
Comparing version 0.1.2 to 0.1.3
{ | ||
"name": "use-jwt-manager", | ||
"author": "claudio biselli", | ||
"version": "0.1.2", | ||
"author": { | ||
"name": "claudio biselli", | ||
"email": "cbiselli89@gmail.com" | ||
}, | ||
"version": "0.1.3", | ||
"description": "hook for jwt auth", | ||
@@ -6,0 +9,0 @@ "repository": { |
@@ -1,2 +0,2 @@ | ||
interface IUser { | ||
interface UserDetails { | ||
id?: number; | ||
@@ -8,4 +8,4 @@ username?: string; | ||
interface IUserContextReducerParams { | ||
user?: IUser; | ||
interface UserContextReducerParams { | ||
user?: UserDetails; | ||
access_token?: string; | ||
@@ -18,26 +18,29 @@ refresh_token?: string; | ||
interface IUserContext extends IUserContextReducerParams { | ||
login: (user: IUser) => void; | ||
logout: () => void; | ||
refrshToken: () => void; | ||
} | ||
interface ITokenParam { | ||
interface TokenParams { | ||
access_token: string; | ||
refresh_token?: string; | ||
[x: string]: any; | ||
} | ||
interface useJwtManagerProps { | ||
refresh: () => Promise<ITokenParam>; | ||
me: { (): Promise<any>; (): Promise<IUser> }; | ||
login: { (user: any): Promise<any>; (arg0: IUser): Promise<ITokenParam> }; | ||
interface jwtManagerProps { | ||
refresh: () => Promise<TokenParams>; | ||
me: () => Promise<UserDetails>; | ||
login: (user: UserDetails) => Promise<TokenParams>; | ||
config: { TOKEN_KEY: string; REFRESH_TOKEN_KEY: string }; | ||
} | ||
interface jwtManagerContext extends IUserContextReducerParams { | ||
login: (user: IUser) => void; | ||
logout: () => void; | ||
refrshToken: () => void; | ||
interface jwtManagerContext extends UserContextReducerParams { | ||
login: (user: UserDetails) => Promise<UserDetails>; | ||
logout: () => Promise<boolean>; | ||
} | ||
export { ITokenParam, IUser, IUserContext, IUserContextReducerParams, useJwtManagerProps, jwtManagerContext }; | ||
class JwtError extends Error { | ||
cause: any; | ||
constructor(message: string, cause: any) { | ||
super(message); | ||
this.cause = cause; | ||
this.name = 'JwtError'; | ||
} | ||
} | ||
export { TokenParams, UserDetails, UserContextReducerParams, jwtManagerProps, jwtManagerContext, JwtError }; |
@@ -1,9 +0,8 @@ | ||
import { IUser, IUserContextReducerParams } from './constants/types'; | ||
import { UserDetails, UserContextReducerParams } from './constants/types'; | ||
type Actions = | ||
| { type: 'LOGIN'; payload: { user: IUser; access_token: string; refresh_token: string } | {} } | ||
| { type: 'ERROR'; payload: { error: string } } | ||
| { type: 'LOGIN'; payload: { user: UserDetails; access_token: string; refresh_token: string } | {} } | ||
| { type: 'LOGOUT' }; | ||
const userContextReducer = (state: IUserContextReducerParams, action: Actions): IUserContextReducerParams => { | ||
const userContextReducer = (state: UserContextReducerParams, action: Actions): UserContextReducerParams => { | ||
switch (action.type) { | ||
@@ -17,4 +16,2 @@ case 'LOGIN': | ||
}; | ||
case 'ERROR': | ||
return { ...state, ...action.payload }; | ||
case 'LOGOUT': | ||
@@ -21,0 +18,0 @@ return { authenticated: false, initialized: true }; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15448
377