Prettier format pending files

This commit is contained in:
Builder.io 2025-11-11 22:23:54 +00:00
parent f4a5768906
commit edb9939638
5 changed files with 52 additions and 39 deletions

View file

@ -38,7 +38,7 @@ export default async (req: Request) => {
if (mainError || !mainUser) {
return new Response(
JSON.stringify({ error: `User ${mainEmail} not found` }),
{ status: 404, headers: { "Content-Type": "application/json" } }
{ status: 404, headers: { "Content-Type": "application/json" } },
);
}
@ -57,12 +57,14 @@ export default async (req: Request) => {
email: devEmail,
user_id: mainUser.user_id,
}),
{ status: 200, headers: { "Content-Type": "application/json" } }
{ status: 200, headers: { "Content-Type": "application/json" } },
);
}
// Link .dev email to main user
const { error: linkError } = await supabase.from("user_email_links").insert({
const { error: linkError } = await supabase
.from("user_email_links")
.insert({
user_id: mainUser.user_id,
email: devEmail,
is_primary: false,
@ -81,7 +83,7 @@ export default async (req: Request) => {
mainEmail,
userId: mainUser.user_id,
}),
{ status: 200, headers: { "Content-Type": "application/json" } }
{ status: 200, headers: { "Content-Type": "application/json" } },
);
} catch (error: any) {
console.error("[Link Dev Email Error]", error);
@ -90,7 +92,7 @@ export default async (req: Request) => {
error: "Failed to link email",
details: error.message,
}),
{ status: 500, headers: { "Content-Type": "application/json" } }
{ status: 500, headers: { "Content-Type": "application/json" } },
);
}
};

View file

@ -15,7 +15,7 @@ export default async (req: Request) => {
if (!primaryEmail || !linkedEmail) {
return new Response(
JSON.stringify({ error: "Missing primaryEmail or linkedEmail" }),
{ status: 400, headers: { "Content-Type": "application/json" } }
{ status: 400, headers: { "Content-Type": "application/json" } },
);
}
@ -32,7 +32,7 @@ export default async (req: Request) => {
error: "Primary email not found",
details: primaryError?.message,
}),
{ status: 404, headers: { "Content-Type": "application/json" } }
{ status: 404, headers: { "Content-Type": "application/json" } },
);
}
@ -49,7 +49,7 @@ export default async (req: Request) => {
error: "Linked email not found",
details: linkedError?.message,
}),
{ status: 404, headers: { "Content-Type": "application/json" } }
{ status: 404, headers: { "Content-Type": "application/json" } },
);
}
@ -138,7 +138,7 @@ export default async (req: Request) => {
// Insert or update primary email
const primaryEmailExists = existingLinks?.some(
(l) => l.email === primaryEmail
(l) => l.email === primaryEmail,
);
if (!primaryEmailExists) {
await supabase.from("user_email_links").insert({
@ -151,7 +151,7 @@ export default async (req: Request) => {
// Insert or update linked email
const linkedEmailExists = existingLinks?.some(
(l) => l.email === linkedEmail
(l) => l.email === linkedEmail,
);
if (!linkedEmailExists) {
await supabase.from("user_email_links").insert({
@ -193,7 +193,7 @@ export default async (req: Request) => {
{
status: 200,
headers: { "Content-Type": "application/json" },
}
},
);
} catch (error: any) {
console.error("[Email Linking Error]", error);
@ -205,7 +205,7 @@ export default async (req: Request) => {
{
status: 500,
headers: { "Content-Type": "application/json" },
}
},
);
}
};

View file

@ -47,7 +47,7 @@ export default async (req: Request) => {
email: primaryEmail,
details: primaryError?.message,
}),
{ status: 404, headers: { "Content-Type": "application/json" } }
{ status: 404, headers: { "Content-Type": "application/json" } },
);
}
@ -65,7 +65,7 @@ export default async (req: Request) => {
email: linkedEmail,
details: linkedError?.message,
}),
{ status: 404, headers: { "Content-Type": "application/json" } }
{ status: 404, headers: { "Content-Type": "application/json" } },
);
}
@ -119,7 +119,7 @@ export default async (req: Request) => {
if (discordLinks && discordLinks.length > 0) {
console.log(
`[Email Linking] Found ${discordLinks.length} discord links, transferring...`
`[Email Linking] Found ${discordLinks.length} discord links, transferring...`,
);
for (const link of discordLinks) {
const { data: existing } = await supabase
@ -145,7 +145,7 @@ export default async (req: Request) => {
if (web3Links && web3Links.length > 0) {
console.log(
`[Email Linking] Found ${web3Links.length} web3 wallets, transferring...`
`[Email Linking] Found ${web3Links.length} web3 wallets, transferring...`,
);
for (const wallet of web3Links) {
const { data: existing } = await supabase
@ -172,7 +172,7 @@ export default async (req: Request) => {
// Insert primary email
const primaryEmailExists = existingLinks?.some(
(l) => l.email === primaryEmail
(l) => l.email === primaryEmail,
);
if (!primaryEmailExists) {
await supabase.from("user_email_links").insert({
@ -185,7 +185,7 @@ export default async (req: Request) => {
// Insert linked email
const linkedEmailExists = existingLinks?.some(
(l) => l.email === linkedEmail
(l) => l.email === linkedEmail,
);
if (!linkedEmailExists) {
await supabase.from("user_email_links").insert({
@ -230,7 +230,7 @@ export default async (req: Request) => {
{
status: 200,
headers: { "Content-Type": "application/json" },
}
},
);
} catch (error: any) {
console.error("[Email Linking Error]", error);
@ -242,7 +242,7 @@ export default async (req: Request) => {
{
status: 500,
headers: { "Content-Type": "application/json" },
}
},
);
}
};

View file

@ -12,10 +12,10 @@ export default async (req: Request) => {
const { email } = await req.json();
if (!email) {
return new Response(
JSON.stringify({ error: "Email is required" }),
{ status: 400, headers: { "Content-Type": "application/json" } }
);
return new Response(JSON.stringify({ error: "Email is required" }), {
status: 400,
headers: { "Content-Type": "application/json" },
});
}
const supabase = getAdminClient();
@ -34,10 +34,10 @@ export default async (req: Request) => {
if (!emailLink) {
// Email is not linked, return the email as-is
return new Response(
JSON.stringify({ primaryEmail: email }),
{ status: 200, headers: { "Content-Type": "application/json" } }
);
return new Response(JSON.stringify({ primaryEmail: email }), {
status: 200,
headers: { "Content-Type": "application/json" },
});
}
// Get the primary email for this user
@ -50,10 +50,10 @@ export default async (req: Request) => {
if (profileError) {
console.error("Profile lookup error:", profileError);
// If we can't find the profile, return original email
return new Response(
JSON.stringify({ primaryEmail: email }),
{ status: 200, headers: { "Content-Type": "application/json" } }
);
return new Response(JSON.stringify({ primaryEmail: email }), {
status: 200,
headers: { "Content-Type": "application/json" },
});
}
return new Response(
@ -62,7 +62,7 @@ export default async (req: Request) => {
linkedFrom: email,
userId: emailLink.user_id,
}),
{ status: 200, headers: { "Content-Type": "application/json" } }
{ status: 200, headers: { "Content-Type": "application/json" } },
);
} catch (error: any) {
console.error("[Resolve Linked Email Error]", error);
@ -74,7 +74,7 @@ export default async (req: Request) => {
{
status: 500,
headers: { "Content-Type": "application/json" },
}
},
);
}
};

View file

@ -9,6 +9,7 @@ The email linking system allows users to authenticate with multiple email addres
### Database Tables
#### `user_email_links`
Links multiple email addresses to a single user account.
```sql
@ -23,6 +24,7 @@ Links multiple email addresses to a single user account.
```
#### `user_profiles` (additions)
```sql
- primary_email: TEXT (the primary email for the account)
- is_dev_account: BOOLEAN (marks if this is a developer account)
@ -72,6 +74,7 @@ UI shows: "Also logged in as mrpiglr@gmail.com"
Resolve a linked email to its primary email address.
**Request:**
```json
{
"email": "mrpiglr@gmail.com"
@ -79,6 +82,7 @@ Resolve a linked email to its primary email address.
```
**Response (linked email):**
```json
{
"primaryEmail": "mrpiglr@aethex.dev",
@ -88,6 +92,7 @@ Resolve a linked email to its primary email address.
```
**Response (non-linked email):**
```json
{
"primaryEmail": "some@email.com"
@ -99,6 +104,7 @@ Resolve a linked email to its primary email address.
Link two existing user accounts by merging one into the other.
**Request:**
```json
{
"primaryEmail": "mrpiglr@aethex.dev",
@ -107,6 +113,7 @@ Link two existing user accounts by merging one into the other.
```
**Response:**
```json
{
"success": true,
@ -121,6 +128,7 @@ Link two existing user accounts by merging one into the other.
Special endpoint to link the mrpiglr accounts.
**Request:**
```bash
curl -X POST https://aethex.dev/api/user/link-mrpiglr-accounts \
-H "Authorization: Bearer mrpiglr-admin-token" \
@ -128,6 +136,7 @@ curl -X POST https://aethex.dev/api/user/link-mrpiglr-accounts \
```
**Response:**
```json
{
"success": true,
@ -168,6 +177,7 @@ When two accounts are merged:
### For Developers (Dev Accounts)
Developer accounts with `@aethex.dev` email:
- `is_dev_account = true`
- `primary_email = "@aethex.dev email"`
- Public profile shows work email
@ -209,6 +219,7 @@ curl -X POST https://aethex.dev/api/user/resolve-linked-email \
Applied via: `code/supabase/migrations/20250206_add_email_linking.sql`
Includes:
- `user_email_links` table with RLS policies
- `get_primary_user_by_email()` function
- Columns on `user_profiles` for dev accounts and primary email