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:
parent
608b744a71
commit
cd28629389
1 changed files with 15 additions and 0 deletions
|
|
@ -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']
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue