Skip to content

Commit

Permalink
Extract Session Cookie Handling
Browse files Browse the repository at this point in the history
Now the cookie token handling takes place in a
own session which can be extended.
  • Loading branch information
schettn committed Jul 29, 2020
1 parent 4d68261 commit 6b3e938
Showing 1 changed file with 31 additions and 16 deletions.
47 changes: 31 additions & 16 deletions src/session/sessions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,31 +63,19 @@ class GithubSession extends Session {
}
}

/** @class A SNEK SubSession */
class SnekSession extends Session {
/** @class CookieSession extends token session handling with cookies */
class CookieSession extends Session {
refreshTokenName: string = "refresh";
/* Define tasks */
public tasks: SnekTasks;

/**
* Initializes a SNEK session.
* Initializes a cookie session.
*
* @constructor
* @author Nico Schett <[email protected]>
* @param {string} sId A session name
* @param {Endpoint} ep A endpoint
* @param {SnekTemplate} template A template set
*/
constructor(
sId: string,
public ep: ApolloEndpoint,
public template: SnekTemplate
) {
constructor(sId: string) {
super(sId);

this.tokenName = sId + "-" + this.tokenName;
this.refreshTokenName = sId + "-" + this.refreshTokenName;
this.tasks = new SnekTasks(this);
}

//> Getter
Expand Down Expand Up @@ -149,6 +137,33 @@ class SnekSession extends Session {
Cookies.remove(this.refreshTokenName);
}
}
}

/** @class A SNEK SubSession */
class SnekSession extends CookieSession {
/* Define tasks */
public tasks: SnekTasks;

/**
* Initializes a SNEK session.
*
* @constructor
* @author Nico Schett <[email protected]>
* @param {string} sId A session name
* @param {Endpoint} ep A endpoint
* @param {SnekTemplate} template A template set
*/
constructor(
sId: string,
public ep: ApolloEndpoint,
public template: SnekTemplate
) {
super(sId);

this.tokenName = sId + "-" + this.tokenName;
this.refreshTokenName = sId + "-" + this.refreshTokenName;
this.tasks = new SnekTasks(this);
}

//> Methods
/**
Expand Down

0 comments on commit 6b3e938

Please sign in to comment.