mirror of
https://github.com/wkulhanek/bonob.git
synced 2025-12-22 01:43:29 +01:00
Login flow working
This commit is contained in:
@@ -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]!;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user