@xk2800/nextjs-template 0.7.1-beta.14 → 0.7.1-beta.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -41,8 +41,16 @@ const OneTap = ({ callbackURL = '/dashboard' }: OneTapProps) => {
41
41
  if (oneTapOffered !== true) return
42
42
  if (!oneTapAllowed) return
43
43
 
44
+ // Passing fetchOptions (and no callbackURL) turns off the client's own redirect, so
45
+ // a 2FA challenge ({ twoFactorRedirect }) isn't overwritten by a jump to callbackURL.
44
46
  authClient.oneTap({
45
- callbackURL,
47
+ fetchOptions: {
48
+ onSuccess: ({ data }) => {
49
+ window.location.href = (data as { twoFactorRedirect?: boolean } | null)?.twoFactorRedirect
50
+ ? `/login/2fa?callbackUrl=${encodeURIComponent(callbackURL)}`
51
+ : callbackURL
52
+ },
53
+ },
46
54
  onPromptNotification: (notification) => {
47
55
  console.log('One Tap prompt notification:', notification)
48
56
  }
@@ -16,8 +16,18 @@ import {
16
16
  AlertDialogTitle,
17
17
  } from '../ui/alert-dialog'
18
18
  import { authClient, useSession } from '../../lib/auth-client'
19
+ import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '../ui/tooltip'
19
20
 
20
- export default function DeleteAccountCard() {
21
+ type Props = {
22
+ /**
23
+ * When set, the Delete account button is disabled (dimmed) and hovering or focusing it
24
+ * shows this text, e.g. "You have an active subscription. Cancel it first." Enforce the
25
+ * same rule on the server too (an auth hook on /delete-user): this only changes the UI.
26
+ */
27
+ disabledReason?: string
28
+ }
29
+
30
+ export default function DeleteAccountCard({ disabledReason }: Props = {}) {
21
31
  const { data: session } = useSession()
22
32
  const email = session?.user.email ?? ''
23
33
  // null = still checking. Credential users confirm with their password;
@@ -78,9 +88,26 @@ export default function DeleteAccountCard() {
78
88
  </CardDescription>
79
89
  </CardHeader>
80
90
  <CardContent>
81
- <Button variant="destructive" onClick={() => setOpen(true)} disabled={hasPassword === null}>
82
- Delete account
83
- </Button>
91
+ {disabledReason ? (
92
+ <TooltipProvider>
93
+ <Tooltip>
94
+ <TooltipTrigger asChild>
95
+ {/* A disabled button gets no pointer events, so this focusable wrapper
96
+ carries the hover / keyboard focus that opens the tooltip. */}
97
+ <span tabIndex={0} aria-label={`Delete account unavailable: ${disabledReason}`} className="inline-block cursor-not-allowed">
98
+ <Button variant="destructive" disabled>
99
+ Delete account
100
+ </Button>
101
+ </span>
102
+ </TooltipTrigger>
103
+ <TooltipContent>{disabledReason}</TooltipContent>
104
+ </Tooltip>
105
+ </TooltipProvider>
106
+ ) : (
107
+ <Button variant="destructive" onClick={() => setOpen(true)} disabled={hasPassword === null}>
108
+ Delete account
109
+ </Button>
110
+ )}
84
111
  </CardContent>
85
112
  </Card>
86
113