Auth.Commands.tsx 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. import { useParams } from 'common'
  2. import type { CommandOptions } from 'ui-patterns/CommandMenu'
  3. import { useRegisterCommands } from 'ui-patterns/CommandMenu'
  4. import { IRouteCommand } from 'ui-patterns/CommandMenu/internal/types'
  5. import { COMMAND_MENU_SECTIONS } from '@/components/interfaces/App/CommandMenu/CommandMenu.utils'
  6. import { useIsFeatureEnabled } from '@/hooks/misc/useIsFeatureEnabled'
  7. export function useAuthGotoCommands(options?: CommandOptions) {
  8. let { ref } = useParams()
  9. ref ||= '_'
  10. const {
  11. authenticationSignInProviders,
  12. authenticationThirdPartyAuth,
  13. authenticationRateLimits,
  14. authenticationEmails,
  15. authenticationMultiFactor,
  16. authenticationAttackProtection,
  17. authenticationPerformance,
  18. } = useIsFeatureEnabled([
  19. 'authentication:sign_in_providers',
  20. 'authentication:third_party_auth',
  21. 'authentication:rate_limits',
  22. 'authentication:emails',
  23. 'authentication:multi_factor',
  24. 'authentication:attack_protection',
  25. 'authentication:performance',
  26. ])
  27. useRegisterCommands(
  28. COMMAND_MENU_SECTIONS.NAVIGATE,
  29. [
  30. {
  31. id: 'nav-auth-users',
  32. name: 'Users',
  33. value: 'Auth: Users',
  34. route: `/project/${ref}/auth/users`,
  35. defaultHidden: true,
  36. },
  37. {
  38. id: 'nav-auth-policies',
  39. name: 'Policies',
  40. value: 'Auth: Policies (RLS)',
  41. route: `/project/${ref}/auth/policies`,
  42. defaultHidden: true,
  43. },
  44. ...(authenticationSignInProviders
  45. ? [
  46. {
  47. id: 'nav-auth-providers',
  48. name: 'Providers',
  49. value: 'Auth: Providers (Social Login, SSO)',
  50. route: `/project/${ref}/auth/providers`,
  51. defaultHidden: true,
  52. } as IRouteCommand,
  53. ]
  54. : []),
  55. ...(authenticationThirdPartyAuth
  56. ? [
  57. {
  58. id: 'nav-auth-providers-third-party',
  59. name: 'Providers (Third Party)',
  60. value: 'Auth: Providers (Third Party)',
  61. route: `/project/${ref}/auth/third-party`,
  62. defaultHidden: true,
  63. } as IRouteCommand,
  64. ]
  65. : []),
  66. {
  67. id: 'nav-auth-sessions',
  68. name: 'Sessions',
  69. value: 'Auth: Sessions (User Sessions)',
  70. route: `/project/${ref}/auth/sessions`,
  71. defaultHidden: true,
  72. },
  73. ...(authenticationRateLimits
  74. ? [
  75. {
  76. id: 'nav-auth-rate-limits',
  77. name: 'Rate Limits',
  78. value: 'Auth: Rate Limits',
  79. route: `/project/${ref}/auth/rate-limits`,
  80. defaultHidden: true,
  81. } as IRouteCommand,
  82. ]
  83. : []),
  84. ...(authenticationEmails
  85. ? [
  86. {
  87. id: 'nav-auth-templates',
  88. name: 'Email Templates',
  89. value: 'Auth: Email Templates',
  90. route: `/project/${ref}/auth/templates`,
  91. defaultHidden: true,
  92. } as IRouteCommand,
  93. {
  94. id: 'nav-auth-smtp',
  95. name: 'SMTP Settings',
  96. value: 'Auth: SMTP Settings (Email Configuration)',
  97. route: `/project/${ref}/auth/smtp`,
  98. defaultHidden: true,
  99. } as IRouteCommand,
  100. ]
  101. : []),
  102. ...(authenticationMultiFactor
  103. ? [
  104. {
  105. id: 'nav-auth-mfa',
  106. name: 'Multi Factor Authentication (MFA)',
  107. value: 'Auth: Multi Factor Authenticaiton (MFA)',
  108. route: `/project/${ref}/auth/mfa`,
  109. defaultHidden: true,
  110. } as IRouteCommand,
  111. ]
  112. : []),
  113. {
  114. id: 'nav-auth-url-configuration',
  115. name: 'URL Configuration',
  116. value: 'Auth: URL Configuration (Site URL, Redirect URLs)',
  117. route: `/project/${ref}/auth/url-configuration`,
  118. defaultHidden: true,
  119. },
  120. ...(authenticationAttackProtection
  121. ? [
  122. {
  123. id: 'nav-auth-attack-protection',
  124. name: 'Attack Protection',
  125. value: 'Auth: Attack Protection',
  126. route: `/project/${ref}/auth/protection`,
  127. defaultHidden: true,
  128. } as IRouteCommand,
  129. ]
  130. : []),
  131. {
  132. id: 'nav-auth-auth-hooks',
  133. name: 'Auth Hooks',
  134. value: 'Auth: Auth Hooks',
  135. route: `/project/${ref}/auth/hooks`,
  136. defaultHidden: true,
  137. },
  138. ...(authenticationPerformance
  139. ? [
  140. {
  141. id: 'nav-auth-performance-settings',
  142. name: 'Auth Performance Settings',
  143. value: 'Auth: Performance Settings',
  144. route: `/project/${ref}/auth/performance`,
  145. defaultHidden: true,
  146. } as IRouteCommand,
  147. ]
  148. : []),
  149. ],
  150. { ...options, deps: [ref] }
  151. )
  152. }