|
1 | 1 | import { auth } from '@/auth'; |
2 | | -import { generateAndStoreAuthCode } from '@/ee/features/oauth/server'; |
3 | 2 | import { LogoutEscapeHatch } from '@/app/components/logoutEscapeHatch'; |
4 | | -import { ClientIcon } from './components/clientIcon'; |
5 | | -import { Button } from '@/components/ui/button'; |
| 3 | +import { ConsentScreen } from './components/consentScreen'; |
6 | 4 | import { prisma } from '@/prisma'; |
7 | 5 | import { hasEntitlement } from '@sourcebot/shared'; |
8 | 6 | import { redirect } from 'next/navigation'; |
9 | | -import logo from '@/public/logo_512.png'; |
10 | | -import Image from 'next/image'; |
11 | 7 |
|
12 | 8 | interface AuthorizePageProps { |
13 | 9 | searchParams: Promise<{ |
@@ -60,97 +56,19 @@ export default async function AuthorizePage({ searchParams }: AuthorizePageProps |
60 | 56 | redirect(`/login?callbackUrl=${encodeURIComponent(callbackUrl)}`); |
61 | 57 | } |
62 | 58 |
|
63 | | - // Server action: user approved the authorization request. |
64 | | - async function handleAllow() { |
65 | | - 'use server'; |
66 | | - const rawCode = await generateAndStoreAuthCode({ |
67 | | - clientId: client_id!, |
68 | | - userId: session!.user.id, |
69 | | - redirectUri: redirect_uri!, |
70 | | - codeChallenge: code_challenge!, |
71 | | - resource: resource ?? null, |
72 | | - }); |
73 | | - |
74 | | - const callbackUrl = new URL(redirect_uri!); |
75 | | - callbackUrl.searchParams.set('code', rawCode); |
76 | | - if (state) callbackUrl.searchParams.set('state', state); |
77 | | - const isWebUrl = callbackUrl.protocol === 'http:' || callbackUrl.protocol === 'https:'; |
78 | | - if (isWebUrl) { |
79 | | - redirect(callbackUrl.toString()); |
80 | | - } else { |
81 | | - redirect(`/oauth/complete?url=${encodeURIComponent(callbackUrl.toString())}`); |
82 | | - } |
83 | | - } |
84 | | - |
85 | | - // Server action: user denied the authorization request. |
86 | | - async function handleDeny() { |
87 | | - 'use server'; |
88 | | - const callbackUrl = new URL(redirect_uri!); |
89 | | - callbackUrl.searchParams.set('error', 'access_denied'); |
90 | | - callbackUrl.searchParams.set('error_description', 'The user denied the authorization request.'); |
91 | | - if (state) callbackUrl.searchParams.set('state', state); |
92 | | - const isWebUrl = callbackUrl.protocol === 'http:' || callbackUrl.protocol === 'https:'; |
93 | | - if (isWebUrl) { |
94 | | - redirect(callbackUrl.toString()); |
95 | | - } else { |
96 | | - redirect(`/oauth/complete?url=${encodeURIComponent(callbackUrl.toString())}`); |
97 | | - } |
98 | | - } |
99 | | - |
100 | 59 | return ( |
101 | 60 | <div className="relative min-h-screen flex items-center justify-center bg-background"> |
102 | 61 | <LogoutEscapeHatch className="absolute top-0 right-0 p-6" /> |
103 | | - <div className="w-full max-w-md rounded-lg border border-border bg-card p-8 shadow-sm"> |
104 | | - |
105 | | - {/* App icons */} |
106 | | - <div className="flex items-center justify-center gap-3 mb-6"> |
107 | | - <ClientIcon name={client.name} logoUri={client.logoUri} /> |
108 | | - <svg className="w-4 h-4 text-muted-foreground" fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={1.5}> |
109 | | - <path strokeLinecap="round" strokeLinejoin="round" d="M8 7h8m0 0-3-3m3 3-3 3M16 17H8m0 0 3 3m-3-3 3-3" /> |
110 | | - </svg> |
111 | | - <Image |
112 | | - src={logo} |
113 | | - alt="Sourcebot" |
114 | | - width={70} |
115 | | - height={70} |
116 | | - className="shrink-0 rounded-xl object-cover" |
117 | | - /> |
118 | | - </div> |
119 | | - |
120 | | - {/* Title */} |
121 | | - <h1 className="text-lg font-semibold text-foreground mb-2"> |
122 | | - <span className="font-bold">{client.name}</span> is requesting access to your Sourcebot account. |
123 | | - </h1> |
124 | | - <p className="text-sm text-muted-foreground text-center mb-6"> |
125 | | - Logged in as <span className="font-medium">{session.user.email}</span> |
126 | | - </p> |
127 | | - |
128 | | - {/* Details table */} |
129 | | - <div className="mb-6 text-sm"> |
130 | | - <p className="text-muted-foreground mb-2">Details</p> |
131 | | - <div className="rounded-md border border-border divide-y divide-border"> |
132 | | - <div className="flex px-4 py-2.5"> |
133 | | - <span className="font-medium text-foreground w-32 shrink-0">Name:</span> |
134 | | - <span>{client.name}</span> |
135 | | - </div> |
136 | | - <div className="flex px-4 py-2.5"> |
137 | | - <span className="font-medium text-foreground w-32 shrink-0">Redirect URI:</span> |
138 | | - <span className="break-all">{redirect_uri}</span> |
139 | | - </div> |
140 | | - </div> |
141 | | - </div> |
142 | | - |
143 | | - {/* Actions */} |
144 | | - <div className="flex justify-end gap-3"> |
145 | | - <form action={handleDeny}> |
146 | | - <Button type="submit" variant="outline">Cancel</Button> |
147 | | - </form> |
148 | | - <form action={handleAllow}> |
149 | | - <Button type="submit">Approve</Button> |
150 | | - </form> |
151 | | - </div> |
152 | | - |
153 | | - </div> |
| 62 | + <ConsentScreen |
| 63 | + clientId={client_id!} |
| 64 | + clientName={client.name} |
| 65 | + clientLogoUri={client.logoUri} |
| 66 | + redirectUri={redirect_uri!} |
| 67 | + codeChallenge={code_challenge!} |
| 68 | + resource={resource ?? null} |
| 69 | + state={state} |
| 70 | + userEmail={session!.user.email!} |
| 71 | + /> |
154 | 72 | </div> |
155 | 73 | ); |
156 | 74 | } |
|
0 commit comments