'use client'
import { useState, useEffect, useCallback } from 'react'
import { useRouter } from 'next/navigation'
import { useAuthStore } from '@/store/authStore'
import api from '@/services/api'
import { useToast } from '@/components/ui/toast'
import { getErrorMessage } from '@/utils/error'
// ---------------------------------------------------------------------------
// Types
// ---------------------------------------------------------------------------
const TOKEN_SCOPES = [
'repo:read',
'repo:write',
'user:read',
'user:write',
'posts:read',
'posts:write',
'webhooks:manage',
] as const
type TokenScope = (typeof TOKEN_SCOPES)[number]
interface PersonalAccessToken {
id: string
name: string
scopes: string[]
lastUsedAt: string | null
createdAt: string
}
interface OAuthApp {
id: string
name: string
clientId: string
redirectUri: string
scopes: string[]
createdAt: string
}
interface AccountWebhook {
id: string
url: string
events: string[]
active: boolean
createdAt: string
}
interface ApiUsageStats {
requestsThisMonth: number
rateLimitTier: string
rateLimitPerHour: number
}
// ---------------------------------------------------------------------------
// Utility helpers
// ---------------------------------------------------------------------------
function formatDate(dateString: string | null): string {
if (!dateString) return 'Never'
return new Date(dateString).toLocaleDateString('en-US', {
year: 'numeric',
month: 'short',
day: 'numeric',
})
}
// ---------------------------------------------------------------------------
// Sub-components
// ---------------------------------------------------------------------------
interface SectionProps {
title: string
description?: string
action?: React.ReactNode
children: React.ReactNode
}
function Section({ title, description, action, children }: SectionProps) {
return (
{description}{title}
{description && (
Failed to load settings
{pageError}
Personal access tokens, OAuth apps, webhooks, and API usage.
You have no personal access tokens yet.
{token.name}
Created {formatDate(token.createdAt)} · Last used{' '} {formatDate(token.lastUsedAt)}
Scopes
You haven't created any OAuth apps.
{app.name}
{app.clientId}
{app.redirectUri}
No webhooks configured.
{webhook.url}
Added {formatDate(webhook.createdAt)}
Requests this month
{usage.requestsThisMonth.toLocaleString()}
Rate limit tier
{usage.rateLimitTier}
Requests / hour
{usage.rateLimitPerHour.toLocaleString()}
Usage data is not available right now.
Make sure to copy your token now. For security reasons,{' '} you won't be able to see it again.
{generatedToken}
Scopes