UNPKG

jwt-logout-app

Version:

A JWT Logout app that maitaines a dictionary of JWTs mapped to a userid which can then be used for performig logout when using JWT for sign-in

40 lines (35 loc) 1.23 kB
import JWTUser from './jwt-user'; let users: JWTUser[] = []; export default class JWTDictionary { /** * */ constructor() { // console.log("Creating new instance of JWT Dictionary"); } public AddUser(user: JWTUser): void { console.log("Adding new user to dictionary"); if (users.indexOf(user) == -1) { users.push(user); console.log("User:" + user.UserId + "added to dictionary"); } } public GetUserByToken(token: string): JWTUser { console.log("Getting user with token:" + token + " from the dictionary"); let foundUser = users.find(x => x.Token === token); console.log("Found user with Id:" + foundUser.UserId + " in dictionary"); return foundUser; } public GetUserBYUserId(userId: string): JWTUser { console.log("Getting user with Id:" + userId + " from the dictionary"); let foundUser = users.find(x => x.UserId === userId); console.log("Found user with Id:" + foundUser.UserId + " in dictionary"); return foundUser; } public RemoveUser(user: JWTUser): void { console.log( "Removing user with Id:" + user.UserId + " from the dictionary" ); users = users.filter(x => x !== user); } }