-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use random token for claiming scratches
- Loading branch information
Showing
8 changed files
with
76 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Generated by Django 5.0 on 2024-01-17 00:43 | ||
|
||
import coreapp.models.scratch | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("coreapp", "0048_remove_scratch_project_function_and_more"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="scratch", | ||
name="claim_token", | ||
field=models.CharField( | ||
default=coreapp.models.scratch.gen_claim_token, max_length=64, null=True | ||
), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
"use client" | ||
|
||
import { useEffect, useRef } from "react" | ||
|
||
import { useRouter } from "next/navigation" | ||
|
||
import LoadingSkeleton from "@/app/scratch/[slug]/loading" | ||
import { post } from "@/lib/api/request" | ||
|
||
export default function Page({ params, searchParams }: { | ||
params: { slug: string } | ||
searchParams: { token: string } | ||
}) { | ||
const router = useRouter() | ||
|
||
// The POST request must happen on the client so | ||
// that the Django session cookie is present. | ||
const effectRan = useRef(false) | ||
useEffect(() => { | ||
if (!effectRan.current) { | ||
post(`/scratch/${params.slug}/claim`, { token: searchParams.token }) | ||
.catch(err => console.error(err)) | ||
.finally(() => router.push(`/scratch/${params.slug}`)) | ||
} | ||
|
||
return () => { | ||
effectRan.current = true | ||
} | ||
}, [params.slug, router, searchParams.token]) | ||
|
||
return <LoadingSkeleton/> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters