mirror of
https://github.com/Drop-OSS/drop.git
synced 2026-07-24 00:42:51 +10:00
another stage of client authentication
This commit is contained in:
@@ -7,7 +7,12 @@ export interface ClientMetadata {
|
||||
|
||||
export class ClientHandler {
|
||||
private temporaryClientTable: {
|
||||
[key: string]: { timeout: NodeJS.Timeout; data: ClientMetadata };
|
||||
[key: string]: {
|
||||
timeout: NodeJS.Timeout;
|
||||
data: ClientMetadata;
|
||||
userId?: string;
|
||||
authToken?: string;
|
||||
};
|
||||
} = {};
|
||||
|
||||
async initiate(metadata: ClientMetadata) {
|
||||
@@ -23,6 +28,28 @@ export class ClientHandler {
|
||||
|
||||
return clientId;
|
||||
}
|
||||
|
||||
async fetchInitiateClientMetadata(clientId: string) {
|
||||
const entry = this.temporaryClientTable[clientId];
|
||||
if (!entry) return undefined;
|
||||
return entry.data;
|
||||
}
|
||||
|
||||
async attachUserId(clientId: string, userId: string) {
|
||||
if (!this.temporaryClientTable[clientId])
|
||||
throw new Error("Invalid clientId for attaching userId");
|
||||
this.temporaryClientTable[clientId].userId = userId;
|
||||
}
|
||||
|
||||
async generateAuthToken(clientId: string) {
|
||||
const entry = this.temporaryClientTable[clientId];
|
||||
if (!entry) throw new Error("Invalid clientId to generate token");
|
||||
|
||||
const token = uuidv4();
|
||||
this.temporaryClientTable[clientId].authToken = token;
|
||||
|
||||
return token;
|
||||
}
|
||||
}
|
||||
|
||||
export const clientHandler = new ClientHandler();
|
||||
|
||||
Reference in New Issue
Block a user