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