Login flow working

This commit is contained in:
simojenki
2021-02-24 20:54:05 +11:00
parent c26a325ee1
commit f295d3f015
13 changed files with 416 additions and 63 deletions

View File

@@ -1,20 +1,39 @@
import { v4 as uuid } from 'uuid';
export type Association = {
authToken: string
userId: string
nickname: string
}
export interface LinkCodes {
mint(): string
clear(): any
count(): Number
has(linkCode: string): boolean
associate(linkCode: string, association: Association): any
associationFor(linkCode: string): Association | undefined
}
export class InMemoryLinkCodes implements LinkCodes {
linkCodes: Record<string, string> = {}
linkCodes: Record<string, Association | undefined> = {}
mint() {
const linkCode = uuid();
this.linkCodes[linkCode] = ""
this.linkCodes[linkCode] = undefined
return linkCode
}
clear = () => { this.linkCodes = {} }
count = () => Object.keys(this.linkCodes).length
has = (linkCode: string) => Object.keys(this.linkCodes).includes(linkCode)
associate = (linkCode: string, association: Association) => {
if(this.has(linkCode))
this.linkCodes[linkCode] = association;
else
throw `Invalid linkCode ${linkCode}`
}
associationFor = (linkCode: string) => {
return this.linkCodes[linkCode]!;
}
}