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

@@ -0,0 +1,35 @@
import {
MusicService,
Credentials,
AuthSuccess,
AuthFailure,
} from "../src/music_service";
export class InMemoryMusicService implements MusicService {
users: Record<string, string> = {};
login({ username, password }: Credentials): AuthSuccess | AuthFailure {
if (
username != undefined &&
password != undefined &&
this.users[username] == password
) {
return { authToken: "token123", userId: username, nickname: username };
} else {
return { message: `Invalid user:${username}` };
}
}
hasUser(credentials: Credentials) {
this.users[credentials.username] = credentials.password;
}
hasNoUsers() {
this.users = {};
}
clear() {
this.users = {};
}
}