Skip to content
This repository was archived by the owner on May 17, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions src/jwt-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
import type {SessionDeps, SessionService} from './types.js';

// Scope path to `data.` here since `jsonwebtoken` has some special top-level keys that we do not want to expose (ex: `exp`)
const getFullPath = keyPath => `data.${keyPath}`;
const getFullPath = (keyPath, dataPath) => `${dataPath}.${keyPath}`;

type JWTConfig = {
secret: string,
Expand All @@ -52,19 +52,29 @@ class JWTSession {
}
return this.token;
}
get(keyPath: string): mixed {
get(keyPath: string, dataPath: string = ''): mixed {
assert(
this.token,
"Cannot access token before loaded, please use this plugin before any of it's dependencies"
);
return get(this.token, getFullPath(keyPath));
if (dataPath === '') {
return get(this.token, keyPath);
} else {
return get(this.token, getFullPath(keyPath, dataPath));
}

}
set(keyPath: string, val: mixed): boolean {
set(keyPath: string, val: mixed, dataPath: string = ''): boolean {
assert(
this.token,
"Cannot access token before loaded, please use this plugin before any of it's dependencies"
);
return set(this.token, getFullPath(keyPath), val);
if (dataPath === '') {
return set(this.token, keyPath, val);
} else {
return set(this.token, getFullPath(keyPath, dataPath), val);
}

}
}

Expand Down
4 changes: 2 additions & 2 deletions src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ export type SessionService = {
ctx: Context
): {
loadToken(): Promise<?Object | string>,
get(keyPath: string): mixed,
set(keyPath: string, val: mixed): boolean,
get(keyPath: string, dataPath: string.optional): mixed,
set(keyPath: string, val: mixed, dataPath: string.optional): boolean,
cookie: string | void,
},
};
Expand Down