Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
try to fix cookie stuff
Browse files
ui/src/app/api/auth/hf/exchange/route.ts
CHANGED
|
@@ -19,7 +19,7 @@ export async function POST(request: NextRequest) {
|
|
| 19 |
}
|
| 20 |
|
| 21 |
const storedState = request.cookies.get(STATE_COOKIE)?.value;
|
| 22 |
-
if (
|
| 23 |
const response = NextResponse.json({ error: 'Invalid or expired OAuth state' }, { status: 400 });
|
| 24 |
response.cookies.delete(STATE_COOKIE);
|
| 25 |
return response;
|
|
|
|
| 19 |
}
|
| 20 |
|
| 21 |
const storedState = request.cookies.get(STATE_COOKIE)?.value;
|
| 22 |
+
if (storedState && state !== storedState) {
|
| 23 |
const response = NextResponse.json({ error: 'Invalid or expired OAuth state' }, { status: 400 });
|
| 24 |
response.cookies.delete(STATE_COOKIE);
|
| 25 |
return response;
|
ui/src/app/api/auth/hf/login/route.ts
CHANGED
|
@@ -10,7 +10,8 @@ export async function GET(request: NextRequest) {
|
|
| 10 |
return NextResponse.json({ error: 'OAuth client ID not configured' }, { status: 500 });
|
| 11 |
}
|
| 12 |
|
| 13 |
-
const
|
|
|
|
| 14 |
const origin = request.nextUrl.origin;
|
| 15 |
const envRedirect =
|
| 16 |
process.env.HF_OAUTH_REDIRECT_URI || process.env.NEXT_PUBLIC_HF_OAUTH_REDIRECT_URI || '';
|
|
@@ -24,15 +25,18 @@ export async function GET(request: NextRequest) {
|
|
| 24 |
authorizeUrl.searchParams.set('state', state);
|
| 25 |
|
| 26 |
const response = NextResponse.redirect(authorizeUrl.toString(), { status: 302 });
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
return response;
|
| 38 |
}
|
|
|
|
| 10 |
return NextResponse.json({ error: 'OAuth client ID not configured' }, { status: 500 });
|
| 11 |
}
|
| 12 |
|
| 13 |
+
const providedState = request.nextUrl.searchParams.get('state');
|
| 14 |
+
const state = providedState || randomUUID();
|
| 15 |
const origin = request.nextUrl.origin;
|
| 16 |
const envRedirect =
|
| 17 |
process.env.HF_OAUTH_REDIRECT_URI || process.env.NEXT_PUBLIC_HF_OAUTH_REDIRECT_URI || '';
|
|
|
|
| 25 |
authorizeUrl.searchParams.set('state', state);
|
| 26 |
|
| 27 |
const response = NextResponse.redirect(authorizeUrl.toString(), { status: 302 });
|
| 28 |
+
|
| 29 |
+
if (!providedState) {
|
| 30 |
+
response.cookies.set({
|
| 31 |
+
name: STATE_COOKIE,
|
| 32 |
+
value: state,
|
| 33 |
+
httpOnly: true,
|
| 34 |
+
sameSite: 'lax',
|
| 35 |
+
secure: process.env.NODE_ENV === 'production',
|
| 36 |
+
maxAge: 60 * 5,
|
| 37 |
+
path: '/',
|
| 38 |
+
});
|
| 39 |
+
}
|
| 40 |
|
| 41 |
return response;
|
| 42 |
}
|
ui/src/app/auth/hf/callback/page.tsx
CHANGED
|
@@ -24,6 +24,14 @@ export default function HFOAuthCallbackPage() {
|
|
| 24 |
}
|
| 25 |
|
| 26 |
if (code && state) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
const success = await exchangeCodeForToken(code, state);
|
| 28 |
if (success) {
|
| 29 |
router.replace('/dashboard');
|
|
|
|
| 24 |
}
|
| 25 |
|
| 26 |
if (code && state) {
|
| 27 |
+
const storedState = sessionStorage.getItem('HF_OAUTH_STATE');
|
| 28 |
+
if (!storedState || storedState !== state) {
|
| 29 |
+
setLocalError('Invalid or expired OAuth state. Please try signing in again.');
|
| 30 |
+
sessionStorage.removeItem('HF_OAUTH_STATE');
|
| 31 |
+
router.replace('/settings');
|
| 32 |
+
return;
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
const success = await exchangeCodeForToken(code, state);
|
| 36 |
if (success) {
|
| 37 |
router.replace('/dashboard');
|
ui/src/app/jobs/new/jobConfig.ts
CHANGED
|
@@ -55,7 +55,7 @@ export const defaultJobConfig: JobConfig = {
|
|
| 55 |
train: {
|
| 56 |
batch_size: 1,
|
| 57 |
bypass_guidance_embedding: true,
|
| 58 |
-
steps:
|
| 59 |
gradient_accumulation: 1,
|
| 60 |
train_unet: true,
|
| 61 |
train_text_encoder: false,
|
|
@@ -83,7 +83,7 @@ export const defaultJobConfig: JobConfig = {
|
|
| 83 |
switch_boundary_every: 1,
|
| 84 |
},
|
| 85 |
model: {
|
| 86 |
-
name_or_path: '
|
| 87 |
quantize: true,
|
| 88 |
qtype: 'qfloat8',
|
| 89 |
quantize_te: true,
|
|
@@ -107,27 +107,6 @@ export const defaultJobConfig: JobConfig = {
|
|
| 107 |
{
|
| 108 |
prompt: 'a horse is a DJ at a night club, fish eye lens, smoke machine, lazer lights, holding a martini',
|
| 109 |
},
|
| 110 |
-
{
|
| 111 |
-
prompt: 'a man showing off his cool new t shirt at the beach, a shark is jumping out of the water in the background',
|
| 112 |
-
},
|
| 113 |
-
{
|
| 114 |
-
prompt: 'a bear building a log cabin in the snow covered mountains',
|
| 115 |
-
},
|
| 116 |
-
{
|
| 117 |
-
prompt: 'woman playing the guitar, on stage, singing a song, laser lights, punk rocker',
|
| 118 |
-
},
|
| 119 |
-
{
|
| 120 |
-
prompt: 'hipster man with a beard, building a chair, in a wood shop',
|
| 121 |
-
},
|
| 122 |
-
{
|
| 123 |
-
prompt: 'photo of a man, white background, medium shot, modeling clothing, studio lighting, white backdrop',
|
| 124 |
-
},
|
| 125 |
-
{
|
| 126 |
-
prompt: "a man holding a sign that says, 'this is a sign'",
|
| 127 |
-
},
|
| 128 |
-
{
|
| 129 |
-
prompt: 'a bulldog, in a post apocalyptic world, with a shotgun, in a leather jacket, in a desert, with a motorcycle',
|
| 130 |
-
},
|
| 131 |
],
|
| 132 |
neg: '',
|
| 133 |
seed: 42,
|
|
|
|
| 55 |
train: {
|
| 56 |
batch_size: 1,
|
| 57 |
bypass_guidance_embedding: true,
|
| 58 |
+
steps: 1200,
|
| 59 |
gradient_accumulation: 1,
|
| 60 |
train_unet: true,
|
| 61 |
train_text_encoder: false,
|
|
|
|
| 83 |
switch_boundary_every: 1,
|
| 84 |
},
|
| 85 |
model: {
|
| 86 |
+
name_or_path: 'Qwen/Qwen-Image',
|
| 87 |
quantize: true,
|
| 88 |
qtype: 'qfloat8',
|
| 89 |
quantize_te: true,
|
|
|
|
| 107 |
{
|
| 108 |
prompt: 'a horse is a DJ at a night club, fish eye lens, smoke machine, lazer lights, holding a martini',
|
| 109 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
],
|
| 111 |
neg: '',
|
| 112 |
seed: 42,
|
ui/src/contexts/AuthContext.tsx
CHANGED
|
@@ -200,6 +200,14 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
|
|
| 200 |
setStatus('error');
|
| 201 |
return false;
|
| 202 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 203 |
setStatus('checking');
|
| 204 |
setError(null);
|
| 205 |
try {
|
|
@@ -223,6 +231,9 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
|
|
| 223 |
namespace: data.namespace || 'user',
|
| 224 |
method: 'oauth',
|
| 225 |
});
|
|
|
|
|
|
|
|
|
|
| 226 |
return true;
|
| 227 |
} catch (err: any) {
|
| 228 |
setError(err?.message || 'Failed to authenticate with Hugging Face');
|
|
@@ -245,7 +256,11 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
|
|
| 245 |
setStatus('checking');
|
| 246 |
setError(null);
|
| 247 |
|
| 248 |
-
window.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 249 |
}, []);
|
| 250 |
|
| 251 |
const logout = useCallback(() => {
|
|
|
|
| 200 |
setStatus('error');
|
| 201 |
return false;
|
| 202 |
}
|
| 203 |
+
if (typeof window !== 'undefined') {
|
| 204 |
+
const storedState = sessionStorage.getItem('HF_OAUTH_STATE');
|
| 205 |
+
if (!storedState || storedState !== state) {
|
| 206 |
+
setError('Invalid or expired OAuth state. Please try again.');
|
| 207 |
+
setStatus('error');
|
| 208 |
+
return false;
|
| 209 |
+
}
|
| 210 |
+
}
|
| 211 |
setStatus('checking');
|
| 212 |
setError(null);
|
| 213 |
try {
|
|
|
|
| 231 |
namespace: data.namespace || 'user',
|
| 232 |
method: 'oauth',
|
| 233 |
});
|
| 234 |
+
if (typeof window !== 'undefined') {
|
| 235 |
+
sessionStorage.removeItem('HF_OAUTH_STATE');
|
| 236 |
+
}
|
| 237 |
return true;
|
| 238 |
} catch (err: any) {
|
| 239 |
setError(err?.message || 'Failed to authenticate with Hugging Face');
|
|
|
|
| 256 |
setStatus('checking');
|
| 257 |
setError(null);
|
| 258 |
|
| 259 |
+
const state = window.crypto.randomUUID();
|
| 260 |
+
sessionStorage.setItem('HF_OAUTH_STATE', state);
|
| 261 |
+
const loginUrl = new URL('/api/auth/hf/login', window.location.origin);
|
| 262 |
+
loginUrl.searchParams.set('state', state);
|
| 263 |
+
window.location.href = loginUrl.toString();
|
| 264 |
}, []);
|
| 265 |
|
| 266 |
const logout = useCallback(() => {
|