Skip to content

Commit

Permalink
revise
Browse files Browse the repository at this point in the history
  • Loading branch information
sunhaolin committed May 13, 2019
1 parent d975860 commit 07ea4ab
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions packages/auth/src/session.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import crypto = require('crypto');
import { getSteedosSchema } from '@steedos/objectql';
import { getSteedosSchema, SteedosUserSession, SteedosIDType } from '@steedos/objectql';

const sessions = {};
const size = 35000;
Expand All @@ -10,12 +10,19 @@ const sessionCacheInMinutes = 10;

interface Session {
name: string;
userId: string;
userId: SteedosIDType;
steedos_id?: string;
email?: string;
expiredAt: number;
}

interface ResultSession {
name: string;
userId: SteedosIDType;
steedos_id?: string;
email?: string;
}

interface SpaceSession {
roles: string[];
expiredAt: number;
Expand Down Expand Up @@ -86,7 +93,7 @@ function assignSession(spaceId, userSession, spaceSession) {
}

function reviseSession(session) {
if (session){
if (session) {
delete session.expiredAt;
}
return session
Expand Down Expand Up @@ -118,7 +125,9 @@ export function getSpaceSessionFromCache(token: string, spaceId: string) {
return spaceSession;
}

export async function getSession(token: string, spaceId?: string) {
export async function getSession(token: string, spaceId: string): Promise<SteedosUserSession>;
export async function getSession(token: string): Promise<ResultSession>;
export async function getSession(token: string, spaceId?: string): Promise<any> {
let expiredAt = new Date().getTime() + sessionCacheInMinutes * 60 * 1000;
let session = getSessionFromCache(token);
if (!session) {
Expand Down

0 comments on commit 07ea4ab

Please sign in to comment.