Skip to content

Commit

Permalink
changes for remote admin api access
Browse files Browse the repository at this point in the history
  • Loading branch information
mkm279 committed Aug 26, 2021
1 parent fef1bbe commit 0f97f0b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
4 changes: 3 additions & 1 deletion lib/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const withAdminCheck = (handler) => {
const kiteKey = req.headers['signalx-kite-key'];
const kiteToken = req.headers['signalx-kite-token'];
if (kiteKey && kiteToken) {
console.log('key and token found in headers. ateempting to connect kite and save session')
try {
const kc = new KiteConnect({
api_key: kiteKey,
Expand All @@ -22,9 +23,10 @@ const withAdminCheck = (handler) => {
const user = { isLoggedIn: true, session: { access_token: kiteToken, ...kiteProfile } }
req.session.set('user', user)
await req.session.save()
console.log('session generated')
} catch (error) {
console.log(error)
return res.status(403).send('Forbidden. Unaithorized kry or token provided')
return res.status(403).send('Forbidden. Unauthorized kry or token provided')
}
}
return handler(req, res)
Expand Down
7 changes: 4 additions & 3 deletions pages/api/trades_day.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import { SignalXUser } from '../../types/misc'

const nanoid = customAlphabet('0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz', 8)

async function createJob (
async function createJob(
{ jobData, user }:
{ jobData: SUPPORTED_TRADE_CONFIG, user: SignalXUser}
{ jobData: SUPPORTED_TRADE_CONFIG, user: SignalXUser }
) {
const {
runAt,
Expand Down Expand Up @@ -73,7 +73,7 @@ async function createJob (
)
}

async function deleteJob (id) {
async function deleteJob(id) {
try {
if (id.includes('repeat')) {
await tradingQueue.removeRepeatableByKey(id)
Expand Down Expand Up @@ -152,6 +152,7 @@ export default withSession(async (req, res) => {
}

if (req.method === 'DELETE') {
console.log("delete request recieved for: ", req.body._id)
try {
const { data } = await axios(`${endpoint}/${req.body._id as string}`)
if (data.queue?.id) {
Expand Down

0 comments on commit 0f97f0b

Please sign in to comment.