Add setEditKey

This method lets us set the edit key in a default header much like we do with user tokens
This commit is contained in:
Justin Edmund 2023-01-31 02:53:29 -08:00
parent 608b744a71
commit cd28629389

View file

@ -1,4 +1,5 @@
import axios from 'axios'
import ls, { get, set } from 'local-storage'
import { getCookie } from 'cookies-next'
import type { NextApiRequest, NextApiResponse } from 'next'
@ -24,3 +25,17 @@ export const setHeaders = (
delete axios.defaults.headers.common['Authorization']
}
}
export const setEditKey = (id: string, user?: User) => {
if (!user) {
const edit_key = get<string>(id)
console.log('Setting header...', edit_key)
axios.defaults.headers.common['X-Edit-Key'] = edit_key
} else {
unsetEditKey()
}
}
export const unsetEditKey = () => {
delete axios.defaults.headers.common['X-Edit-Key']
}