full
This commit is contained in:
80
routes/application/auth/index.js
Normal file
80
routes/application/auth/index.js
Normal file
@@ -0,0 +1,80 @@
|
||||
const express = require('express')
|
||||
const router = express.Router()
|
||||
const authRateLimit = require('../../../middlewares/authRateLimit')
|
||||
const blockCheck = require('../../../middlewares/blockCheck')
|
||||
const {
|
||||
googleAuth,
|
||||
linkGoogleAccount,
|
||||
getGoogleLinkStatus,
|
||||
} = require('../../../controllers/application/auth/googleController')
|
||||
const {
|
||||
instagramAuth,
|
||||
linkInstagramAccount,
|
||||
getInstagramLinkStatus,
|
||||
disconnectInstagram,
|
||||
} = require('../../../controllers/application/auth/instagramController')
|
||||
const {
|
||||
getInstagramMedia,
|
||||
importInstagramPosts,
|
||||
disableAutoImport,
|
||||
} = require('../../../controllers/application/auth/instagramImportController')
|
||||
const {
|
||||
instagramDeauthorize,
|
||||
instagramDataDeletion,
|
||||
} = require('../../../controllers/application/auth/instagramComplianceController')
|
||||
const {
|
||||
getTotpStatus,
|
||||
setupTotp,
|
||||
enableTotp,
|
||||
disableTotp,
|
||||
verifyLoginTotp,
|
||||
} = require('../../../controllers/application/auth/totpController')
|
||||
|
||||
function resolveAsyncHandler () {
|
||||
try {
|
||||
const mod = require('../../../utils/asyncHandler')
|
||||
if (typeof mod === 'function') return mod
|
||||
if (typeof mod?.asyncHandler === 'function') return mod.asyncHandler
|
||||
} catch (err) {
|
||||
console.error('[auth] asyncHandler module missing/invalid:', err?.message || err)
|
||||
}
|
||||
|
||||
// fallback محلی تا سرور به خاطر نبودن util بالا نیاید
|
||||
return (handler) => (req, res, next) => {
|
||||
Promise.resolve(handler(req, res, next)).catch((error) => {
|
||||
console.error('[asyncHandler:fallback]', error)
|
||||
if (res.headersSent) return next(error)
|
||||
return res.status(error?.status || 500).json({
|
||||
message: error?.userMessage || 'خطای سرور',
|
||||
en_message: error?.message || 'internal_error',
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
const asyncHandler = resolveAsyncHandler()
|
||||
|
||||
router.post('/google', authRateLimit, asyncHandler(googleAuth))
|
||||
router.post('/google/link', blockCheck, asyncHandler(linkGoogleAccount))
|
||||
router.get('/google/status', blockCheck, asyncHandler(getGoogleLinkStatus))
|
||||
|
||||
router.post('/instagram/callback', authRateLimit, asyncHandler(instagramAuth))
|
||||
router.post('/instagram/link', blockCheck, asyncHandler(linkInstagramAccount))
|
||||
router.get('/instagram/status', blockCheck, asyncHandler(getInstagramLinkStatus))
|
||||
router.post('/instagram/disconnect', blockCheck, asyncHandler(disconnectInstagram))
|
||||
router.get('/instagram/media', blockCheck, asyncHandler(getInstagramMedia))
|
||||
router.post('/instagram/import', blockCheck, asyncHandler(importInstagramPosts))
|
||||
router.post('/instagram/import/auto-update', blockCheck, asyncHandler(disableAutoImport))
|
||||
|
||||
// Called server-to-server by Meta (signed_request, no user session) — registered as the
|
||||
// "Deauthorize callback URL" / "Data deletion request URL" in Instagram Business Login settings.
|
||||
router.post('/instagram/deauthorize', authRateLimit, asyncHandler(instagramDeauthorize))
|
||||
router.post('/instagram/data-deletion', authRateLimit, asyncHandler(instagramDataDeletion))
|
||||
|
||||
router.get('/totp/status', blockCheck, asyncHandler(getTotpStatus))
|
||||
router.post('/totp/setup', blockCheck, asyncHandler(setupTotp))
|
||||
router.post('/totp/enable', blockCheck, asyncHandler(enableTotp))
|
||||
router.post('/totp/disable', blockCheck, asyncHandler(disableTotp))
|
||||
router.post('/totp/verify-login', authRateLimit, asyncHandler(verifyLoginTotp))
|
||||
|
||||
module.exports = router
|
||||
Reference in New Issue
Block a user