add change redirect uri from oauth
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
'use client';
|
||||
|
||||
import { Copy, ExternalLink, KeyRound, RefreshCw, Trash2 } from 'lucide-react';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { Copy, ExternalLink, KeyRound, Loader2, RefreshCw, Trash2 } from 'lucide-react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/dialog';
|
||||
import { OAuthClient } from '@/lib/api';
|
||||
@@ -28,7 +29,8 @@ export function OAuthClientDetailDialog({
|
||||
onCopy,
|
||||
onRotateSecret,
|
||||
onToggleActive,
|
||||
onDelete
|
||||
onDelete,
|
||||
onSaveRedirectUris
|
||||
}: {
|
||||
client: OAuthClient | null;
|
||||
endpoints: OAuthEndpoints;
|
||||
@@ -38,7 +40,16 @@ export function OAuthClientDetailDialog({
|
||||
onRotateSecret: (clientId: string) => void;
|
||||
onToggleActive: (client: OAuthClient) => void;
|
||||
onDelete: (client: OAuthClient) => void;
|
||||
onSaveRedirectUris: (client: OAuthClient, redirectUris: string[]) => Promise<void>;
|
||||
}) {
|
||||
const [redirectUrisDraft, setRedirectUrisDraft] = useState('');
|
||||
const [savingRedirectUris, setSavingRedirectUris] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (!client) return;
|
||||
setRedirectUrisDraft(client.redirectUris.join('\n'));
|
||||
}, [client]);
|
||||
|
||||
if (!client) return null;
|
||||
|
||||
const primaryRedirect = client.redirectUris[0] ?? 'https://app.example.com/oauth/callback';
|
||||
@@ -77,7 +88,48 @@ export function OAuthClientDetailDialog({
|
||||
Client Secret выдаётся один раз при создании или после «Новый secret». Храните только на backend.
|
||||
</p>
|
||||
) : null}
|
||||
<CopyRow label="Redirect URI" value={client.redirectUris.join('\n')} onCopy={onCopy} />
|
||||
<div className="space-y-2">
|
||||
<div className="flex items-center justify-between gap-2">
|
||||
<span className="font-medium">Redirect URI</span>
|
||||
{client.canManage ? null : (
|
||||
<Button variant="ghost" size="icon" aria-label="Скопировать Redirect URI" onClick={() => onCopy(client.redirectUris.join('\n'), 'Redirect URI')}>
|
||||
<Copy className="h-4 w-4" />
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
{client.canManage ? (
|
||||
<>
|
||||
<textarea
|
||||
value={redirectUrisDraft}
|
||||
onChange={(event) => setRedirectUrisDraft(event.target.value)}
|
||||
placeholder="https://app.example.com/oauth/callback"
|
||||
className="min-h-[96px] w-full rounded-xl border border-[#eceef4] bg-white px-3 py-2 text-sm"
|
||||
/>
|
||||
<p className="text-xs text-[#667085]">
|
||||
По одному URI на строку. Должен точно совпадать с redirect_uri в запросе authorize (протокол, домен, путь, слэш).
|
||||
</p>
|
||||
<Button
|
||||
size="sm"
|
||||
disabled={savingRedirectUris}
|
||||
onClick={() => {
|
||||
const redirectUris = redirectUrisDraft
|
||||
.split('\n')
|
||||
.map((item) => item.trim())
|
||||
.filter(Boolean);
|
||||
setSavingRedirectUris(true);
|
||||
void onSaveRedirectUris(client, redirectUris).finally(() => setSavingRedirectUris(false));
|
||||
}}
|
||||
>
|
||||
{savingRedirectUris ? <Loader2 className="mr-2 h-4 w-4 animate-spin" /> : null}
|
||||
Сохранить redirect URI
|
||||
</Button>
|
||||
</>
|
||||
) : (
|
||||
<div className="rounded-2xl bg-[#f4f5f8] p-4 text-sm">
|
||||
<code className="block whitespace-pre-wrap break-all text-xs">{client.redirectUris.join('\n')}</code>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<CopyRow label="Scopes" value={scope} onCopy={onCopy} />
|
||||
</section>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user