AuthLayout.utils.ts 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. import { useFlag, useParams } from 'common'
  2. import type { ProductMenuGroup } from '@/components/ui/ProductMenu/ProductMenu.types'
  3. import { useIsFeatureEnabled } from '@/hooks/misc/useIsFeatureEnabled'
  4. import { IS_PLATFORM } from '@/lib/constants'
  5. import { SHORTCUT_IDS } from '@/state/shortcuts/registry'
  6. export interface GenerateAuthMenuOptions {
  7. ref?: string
  8. isPlatform: boolean
  9. showOverview: boolean
  10. features: {
  11. signInProviders: boolean
  12. rateLimits: boolean
  13. emails: boolean
  14. multiFactor: boolean
  15. attackProtection: boolean
  16. performance: boolean
  17. passkeys?: boolean
  18. }
  19. }
  20. export function generateAuthMenu(options: GenerateAuthMenuOptions): ProductMenuGroup[] {
  21. const { ref, isPlatform, showOverview, features } = options
  22. const passkeysInMenu = Boolean(features.passkeys)
  23. const baseUrl = `/project/${ref}/auth`
  24. return [
  25. {
  26. title: 'Manage',
  27. items: [
  28. ...(showOverview
  29. ? [
  30. {
  31. name: 'Overview',
  32. key: 'overview',
  33. url: `${baseUrl}/overview`,
  34. items: [],
  35. shortcutId: SHORTCUT_IDS.NAV_AUTH_OVERVIEW,
  36. },
  37. ]
  38. : []),
  39. {
  40. name: 'Users',
  41. key: 'users',
  42. url: `${baseUrl}/users`,
  43. items: [],
  44. shortcutId: SHORTCUT_IDS.NAV_AUTH_USERS,
  45. },
  46. ...(isPlatform
  47. ? [
  48. {
  49. name: 'OAuth Apps',
  50. key: 'oauth-apps',
  51. url: `${baseUrl}/oauth-apps`,
  52. items: [],
  53. shortcutId: SHORTCUT_IDS.NAV_AUTH_OAUTH_APPS,
  54. },
  55. ]
  56. : []),
  57. ],
  58. },
  59. ...(features.emails && isPlatform
  60. ? [
  61. {
  62. title: 'Notifications',
  63. items: [
  64. ...(features.emails
  65. ? [
  66. {
  67. name: 'Emails',
  68. key: 'email',
  69. pages: ['templates', 'smtp'],
  70. url: `${baseUrl}/templates`,
  71. items: [],
  72. shortcutId: SHORTCUT_IDS.NAV_AUTH_EMAIL,
  73. },
  74. ]
  75. : []),
  76. ],
  77. },
  78. ]
  79. : []),
  80. {
  81. title: 'Configuration',
  82. items: [
  83. {
  84. name: 'Policies',
  85. key: 'policies',
  86. url: `${baseUrl}/policies`,
  87. items: [],
  88. shortcutId: SHORTCUT_IDS.NAV_AUTH_POLICIES,
  89. },
  90. ...(isPlatform
  91. ? [
  92. ...(features.signInProviders
  93. ? [
  94. {
  95. name: 'Sign In / Providers',
  96. key: 'sign-in-up',
  97. pages: ['providers', 'third-party'],
  98. url: `${baseUrl}/providers`,
  99. items: [],
  100. shortcutId: SHORTCUT_IDS.NAV_AUTH_SIGN_IN,
  101. },
  102. ]
  103. : []),
  104. ...(passkeysInMenu
  105. ? [
  106. {
  107. name: 'Passkeys',
  108. key: 'passkeys',
  109. url: `${baseUrl}/passkeys`,
  110. label: 'Beta',
  111. shortcutId: SHORTCUT_IDS.NAV_AUTH_PASSKEYS,
  112. },
  113. ]
  114. : []),
  115. {
  116. name: 'OAuth Server',
  117. key: 'oauth-server',
  118. url: `${baseUrl}/oauth-server`,
  119. label: 'Beta',
  120. shortcutId: SHORTCUT_IDS.NAV_AUTH_OAUTH_SERVER,
  121. },
  122. {
  123. name: 'Sessions',
  124. key: 'sessions',
  125. url: `${baseUrl}/sessions`,
  126. items: [],
  127. shortcutId: SHORTCUT_IDS.NAV_AUTH_SESSIONS,
  128. },
  129. ...(features.rateLimits
  130. ? [
  131. {
  132. name: 'Rate Limits',
  133. key: 'rate-limits',
  134. url: `${baseUrl}/rate-limits`,
  135. items: [],
  136. shortcutId: SHORTCUT_IDS.NAV_AUTH_RATE_LIMITS,
  137. },
  138. ]
  139. : []),
  140. ...(features.multiFactor
  141. ? [
  142. {
  143. name: 'Multi-Factor',
  144. key: 'mfa',
  145. url: `${baseUrl}/mfa`,
  146. items: [],
  147. shortcutId: SHORTCUT_IDS.NAV_AUTH_MFA,
  148. },
  149. ]
  150. : []),
  151. {
  152. name: 'URL Configuration',
  153. key: 'url-configuration',
  154. url: `${baseUrl}/url-configuration`,
  155. items: [],
  156. shortcutId: SHORTCUT_IDS.NAV_AUTH_URL_CONFIGURATION,
  157. },
  158. ...(features.attackProtection
  159. ? [
  160. {
  161. name: 'Attack Protection',
  162. key: 'protection',
  163. url: `${baseUrl}/protection`,
  164. items: [],
  165. shortcutId: SHORTCUT_IDS.NAV_AUTH_PROTECTION,
  166. },
  167. ]
  168. : []),
  169. {
  170. name: 'Auth Hooks',
  171. key: 'hooks',
  172. url: `${baseUrl}/hooks`,
  173. items: [],
  174. label: 'Beta',
  175. shortcutId: SHORTCUT_IDS.NAV_AUTH_HOOKS,
  176. },
  177. {
  178. name: 'Audit Logs',
  179. key: 'audit-logs',
  180. url: `${baseUrl}/audit-logs`,
  181. items: [],
  182. shortcutId: SHORTCUT_IDS.NAV_AUTH_AUDIT_LOGS,
  183. },
  184. ...(features.performance
  185. ? [
  186. {
  187. name: 'Performance',
  188. key: 'performance',
  189. url: `${baseUrl}/performance`,
  190. items: [],
  191. shortcutId: SHORTCUT_IDS.NAV_AUTH_PERFORMANCE,
  192. },
  193. ]
  194. : []),
  195. ]
  196. : []),
  197. ],
  198. },
  199. ]
  200. }
  201. export const useGenerateAuthMenu = (): ProductMenuGroup[] => {
  202. const { ref } = useParams()
  203. const showOverview = useFlag('authOverviewPage')
  204. const enablePasskeyAuth = useFlag('enablePasskeyAuth')
  205. const {
  206. authenticationSignInProviders,
  207. authenticationRateLimits,
  208. authenticationEmails,
  209. authenticationMultiFactor,
  210. authenticationAttackProtection,
  211. authenticationPerformance,
  212. } = useIsFeatureEnabled([
  213. 'authentication:sign_in_providers',
  214. 'authentication:rate_limits',
  215. 'authentication:emails',
  216. 'authentication:multi_factor',
  217. 'authentication:attack_protection',
  218. 'authentication:performance',
  219. ])
  220. return generateAuthMenu({
  221. ref,
  222. isPlatform: IS_PLATFORM,
  223. showOverview,
  224. features: {
  225. signInProviders: authenticationSignInProviders,
  226. rateLimits: authenticationRateLimits,
  227. emails: authenticationEmails,
  228. multiFactor: authenticationMultiFactor,
  229. attackProtection: authenticationAttackProtection,
  230. performance: authenticationPerformance,
  231. passkeys: enablePasskeyAuth,
  232. },
  233. })
  234. }