use-jwt-manager
Advanced tools
Comparing version 0.1.82 to 0.2.0
@@ -7,3 +7,3 @@ { | ||
}, | ||
"version": "0.1.82", | ||
"version": "0.2.0", | ||
"description": "hook for jwt auth", | ||
@@ -10,0 +10,0 @@ "repository": { |
@@ -10,4 +10,3 @@ interface UserDetails { | ||
user?: UserDetails; | ||
access_token?: string; | ||
refresh_token?: string; | ||
token?: string; | ||
initialized?: boolean; | ||
@@ -19,4 +18,3 @@ authenticated?: boolean; | ||
interface TokenParams { | ||
access_token: string; | ||
refresh_token?: string; | ||
token: string; | ||
[x: string]: any; | ||
@@ -29,3 +27,3 @@ } | ||
login: (user: UserDetails) => Promise<TokenParams>; | ||
config: { TOKEN_KEY: string; REFRESH_TOKEN_KEY: string }; | ||
config: { TOKEN_KEY: string }; | ||
} | ||
@@ -36,3 +34,3 @@ | ||
logout: () => Promise<boolean>; | ||
refresh: () => void | ||
refresh: () => void; | ||
} | ||
@@ -39,0 +37,0 @@ |
import { UserDetails, UserContextReducerParams } from './constants/types'; | ||
type Actions = | ||
| { type: 'LOGIN'; payload: { user: UserDetails; access_token: string; refresh_token: string } | {} } | ||
| { type: 'LOGOUT' }; | ||
type Actions = { type: 'LOGIN'; payload: { user: UserDetails; token: string } | {} } | { type: 'LOGOUT' }; | ||
@@ -7,0 +5,0 @@ const userContextReducer = (state: UserContextReducerParams, action: Actions): UserContextReducerParams => { |
@@ -9,3 +9,3 @@ { | ||
"sourceMap": true, | ||
"target": "ESNext", | ||
"target": "es6", | ||
"allowJs": true, | ||
@@ -19,10 +19,10 @@ "checkJs": false, | ||
"esModuleInterop": true, | ||
"lib": ["dom", "dom.iterable", "ESNext"], | ||
"lib": ["DOM", "ESNext"], | ||
"allowSyntheticDefaultImports": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"resolveJsonModule": true, | ||
"declaration": true, | ||
"declaration": true | ||
}, | ||
"include": ["src"], | ||
"exclude": ["node_modules", "**/*.spec.ts"] | ||
} | ||
} |
@@ -8,9 +8,6 @@ import Lockr from 'lockr'; | ||
const TOKEN_KEY = 'BANANA'; | ||
const REFRESH_TOKEN_KEY = 'BANANA_ROTATE'; | ||
function refresh(forceFail = false) { | ||
return new Promise<TokenParams>((resolve, reject) => { | ||
forceFail | ||
? reject({ code: 'B4N4N41', description: 'refresh stuff' }) | ||
: resolve({ access_token: 'new_at1', refresh_token: 'new_rt1' }); | ||
forceFail ? reject({ code: 'B4N4N41', description: 'refresh stuff' }) : resolve({ token: 'new_at1' }); | ||
}); | ||
@@ -28,9 +25,9 @@ } | ||
if (user.username == 'finto') { | ||
resolve({ access_token: 'new_at2', refresh_token: 'new_rt2' }); | ||
resolve({ token: 'new_at2' }); | ||
} | ||
reject({ code: 'B4N4N43', description: 'login stuff' }); | ||
reject({ code: 'B4N4N43' }); | ||
}); | ||
} | ||
const config = { TOKEN_KEY, REFRESH_TOKEN_KEY }; | ||
const config = { TOKEN_KEY }; | ||
@@ -45,10 +42,8 @@ test('not authenticated if no jwt present in ls at start', () => { | ||
expect(Lockr.get(TOKEN_KEY)).toBe(undefined); | ||
expect(Lockr.get(REFRESH_TOKEN_KEY)).toBe(undefined); | ||
}); | ||
test('authenticated if jw present at start', async () => { | ||
Lockr.rm(TOKEN_KEY); | ||
Lockr.rm(REFRESH_TOKEN_KEY); | ||
Lockr.set(REFRESH_TOKEN_KEY, 'old_rt'); | ||
Lockr.set(TOKEN_KEY, 'old_token'); | ||
const { result, waitForNextUpdate } = renderHook(() => useJWT({ login, me, refresh, config })); | ||
console.log(result.current); | ||
await waitForNextUpdate(); | ||
@@ -59,7 +54,5 @@ // assert initial state | ||
expect(result.current.user).toEqual(USER); | ||
expect(result.current.access_token).toEqual('new_at1'); | ||
expect(result.current.refresh_token).toEqual('new_rt1'); | ||
expect(result.current.token).toEqual('new_at1'); | ||
expect(Lockr.get(TOKEN_KEY)).toEqual('new_at1'); | ||
expect(Lockr.get(REFRESH_TOKEN_KEY)).toEqual('new_rt1'); | ||
}); | ||
@@ -69,3 +62,2 @@ | ||
Lockr.rm(TOKEN_KEY); | ||
Lockr.rm(REFRESH_TOKEN_KEY); | ||
const { result, waitForNextUpdate } = renderHook(() => useJWT({ login, me, refresh, config })); | ||
@@ -86,6 +78,4 @@ | ||
expect(result.current.user).toEqual(USER); | ||
expect(result.current.access_token).toEqual('new_at2'); | ||
expect(result.current.refresh_token).toEqual('new_rt2'); | ||
expect(result.current.token).toEqual('new_at2'); | ||
expect(Lockr.get(TOKEN_KEY)).toEqual('new_at2'); | ||
expect(Lockr.get(REFRESH_TOKEN_KEY)).toEqual('new_rt2'); | ||
@@ -100,6 +90,4 @@ await act(async () => { | ||
expect(result.current.user).toBe(undefined); | ||
expect(result.current.access_token).toBe(undefined); | ||
expect(result.current.refresh_token).toBe(undefined); | ||
expect(result.current.token).toBe(undefined); | ||
expect(Lockr.get(TOKEN_KEY)).toBe(undefined); | ||
expect(Lockr.get(REFRESH_TOKEN_KEY)).toBe(undefined); | ||
}); | ||
@@ -109,3 +97,2 @@ | ||
Lockr.rm(TOKEN_KEY); | ||
Lockr.rm(REFRESH_TOKEN_KEY); | ||
const { result, waitForNextUpdate } = renderHook(() => useJWT({ login, me, refresh, config })); | ||
@@ -128,7 +115,5 @@ | ||
expect(result.current.user).toBe(undefined); | ||
expect(result.current.access_token).toBe(undefined); | ||
expect(result.current.refresh_token).toBe(undefined); | ||
expect(result.current.token).toBe(undefined); | ||
expect(Lockr.get(TOKEN_KEY)).toBe(undefined); | ||
expect(Lockr.get(REFRESH_TOKEN_KEY)).toBe(undefined); | ||
}); |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
2
0
13527
10
290