Use kv datastore for auth (#272)
This commit is contained in:
parent
d741351e26
commit
b6cab643ef
10 changed files with 143 additions and 173 deletions
26
lib/utils.ts
26
lib/utils.ts
|
|
@ -61,3 +61,29 @@ export const getStringFromBuffer = (buffer: ArrayBuffer) =>
|
|||
Array.from(new Uint8Array(buffer))
|
||||
.map(b => b.toString(16).padStart(2, '0'))
|
||||
.join('')
|
||||
|
||||
export enum ResultCode {
|
||||
InvalidCredentials = 'INVALID_CREDENTIALS',
|
||||
InvalidSubmission = 'INVALID_SUBMISSION',
|
||||
UserAlreadyExists = 'USER_ALREADY_EXISTS',
|
||||
UnknownError = 'UNKNOWN_ERROR',
|
||||
UserCreated = 'USER_CREATED',
|
||||
UserLoggedIn = 'USER_LOGGED_IN'
|
||||
}
|
||||
|
||||
export const getMessageFromCode = (resultCode: string) => {
|
||||
switch (resultCode) {
|
||||
case ResultCode.InvalidCredentials:
|
||||
return 'Invalid credentials!'
|
||||
case ResultCode.InvalidSubmission:
|
||||
return 'Invalid submission, please try again!'
|
||||
case ResultCode.UserAlreadyExists:
|
||||
return 'User already exists, please log in!'
|
||||
case ResultCode.UserCreated:
|
||||
return 'User created, welcome!'
|
||||
case ResultCode.UnknownError:
|
||||
return 'Something went wrong, please try again!'
|
||||
case ResultCode.UserLoggedIn:
|
||||
return 'Logged in!'
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue