Skip to content

Commit

Permalink
Bugfix: Creating a new api key would crash when there didn't exist an…
Browse files Browse the repository at this point in the history
…y api keys
  • Loading branch information
runely committed Jun 10, 2022
1 parent 8c467bd commit 633626e
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/mocks/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { API } from '../config'
import { add, get, put, remove } from './mock-data'
import { getRandomHex, getRandomNumber } from './lib/helpers'

import _apikeys from './data/apikeys.json'

const getReqSearchParams = req => {
const searchParams = new URLSearchParams(req.url.search)
const params = {}
Expand Down Expand Up @@ -70,7 +72,8 @@ export const handlers = [
rest.post(`${API.URL}/apikeys`, (req, res, ctx) => {
const { fullitem } = getReqSearchParams(req)
const apiKeys = get({ top: getTop(req), type: 'apikeys' })
const newApiKey = JSON.parse(JSON.stringify(apiKeys.data[0]))
const copyApiKey = apiKeys.data.length > 0 ? apiKeys.data[0] : _apikeys[0]
const newApiKey = JSON.parse(JSON.stringify(copyApiKey))

newApiKey._id = `${newApiKey._id.slice(0, -10)}${getRandomHex(10)}`
newApiKey.hash = getRandomHex(128)
Expand Down

0 comments on commit 633626e

Please sign in to comment.