Prettier format pending files
This commit is contained in:
parent
f4a5768906
commit
edb9939638
5 changed files with 52 additions and 39 deletions
|
|
@ -38,7 +38,7 @@ export default async (req: Request) => {
|
||||||
if (mainError || !mainUser) {
|
if (mainError || !mainUser) {
|
||||||
return new Response(
|
return new Response(
|
||||||
JSON.stringify({ error: `User ${mainEmail} not found` }),
|
JSON.stringify({ error: `User ${mainEmail} not found` }),
|
||||||
{ status: 404, headers: { "Content-Type": "application/json" } }
|
{ status: 404, headers: { "Content-Type": "application/json" } },
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -57,17 +57,19 @@ export default async (req: Request) => {
|
||||||
email: devEmail,
|
email: devEmail,
|
||||||
user_id: mainUser.user_id,
|
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
|
// Link .dev email to main user
|
||||||
const { error: linkError } = await supabase.from("user_email_links").insert({
|
const { error: linkError } = await supabase
|
||||||
user_id: mainUser.user_id,
|
.from("user_email_links")
|
||||||
email: devEmail,
|
.insert({
|
||||||
is_primary: false,
|
user_id: mainUser.user_id,
|
||||||
verified_at: new Date().toISOString(),
|
email: devEmail,
|
||||||
});
|
is_primary: false,
|
||||||
|
verified_at: new Date().toISOString(),
|
||||||
|
});
|
||||||
|
|
||||||
if (linkError) {
|
if (linkError) {
|
||||||
throw linkError;
|
throw linkError;
|
||||||
|
|
@ -81,7 +83,7 @@ export default async (req: Request) => {
|
||||||
mainEmail,
|
mainEmail,
|
||||||
userId: mainUser.user_id,
|
userId: mainUser.user_id,
|
||||||
}),
|
}),
|
||||||
{ status: 200, headers: { "Content-Type": "application/json" } }
|
{ status: 200, headers: { "Content-Type": "application/json" } },
|
||||||
);
|
);
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.error("[Link Dev Email Error]", error);
|
console.error("[Link Dev Email Error]", error);
|
||||||
|
|
@ -90,7 +92,7 @@ export default async (req: Request) => {
|
||||||
error: "Failed to link email",
|
error: "Failed to link email",
|
||||||
details: error.message,
|
details: error.message,
|
||||||
}),
|
}),
|
||||||
{ status: 500, headers: { "Content-Type": "application/json" } }
|
{ status: 500, headers: { "Content-Type": "application/json" } },
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ export default async (req: Request) => {
|
||||||
if (!primaryEmail || !linkedEmail) {
|
if (!primaryEmail || !linkedEmail) {
|
||||||
return new Response(
|
return new Response(
|
||||||
JSON.stringify({ error: "Missing primaryEmail or linkedEmail" }),
|
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",
|
error: "Primary email not found",
|
||||||
details: primaryError?.message,
|
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",
|
error: "Linked email not found",
|
||||||
details: linkedError?.message,
|
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
|
// Insert or update primary email
|
||||||
const primaryEmailExists = existingLinks?.some(
|
const primaryEmailExists = existingLinks?.some(
|
||||||
(l) => l.email === primaryEmail
|
(l) => l.email === primaryEmail,
|
||||||
);
|
);
|
||||||
if (!primaryEmailExists) {
|
if (!primaryEmailExists) {
|
||||||
await supabase.from("user_email_links").insert({
|
await supabase.from("user_email_links").insert({
|
||||||
|
|
@ -151,7 +151,7 @@ export default async (req: Request) => {
|
||||||
|
|
||||||
// Insert or update linked email
|
// Insert or update linked email
|
||||||
const linkedEmailExists = existingLinks?.some(
|
const linkedEmailExists = existingLinks?.some(
|
||||||
(l) => l.email === linkedEmail
|
(l) => l.email === linkedEmail,
|
||||||
);
|
);
|
||||||
if (!linkedEmailExists) {
|
if (!linkedEmailExists) {
|
||||||
await supabase.from("user_email_links").insert({
|
await supabase.from("user_email_links").insert({
|
||||||
|
|
@ -193,7 +193,7 @@ export default async (req: Request) => {
|
||||||
{
|
{
|
||||||
status: 200,
|
status: 200,
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.error("[Email Linking Error]", error);
|
console.error("[Email Linking Error]", error);
|
||||||
|
|
@ -205,7 +205,7 @@ export default async (req: Request) => {
|
||||||
{
|
{
|
||||||
status: 500,
|
status: 500,
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ export default async (req: Request) => {
|
||||||
email: primaryEmail,
|
email: primaryEmail,
|
||||||
details: primaryError?.message,
|
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,
|
email: linkedEmail,
|
||||||
details: linkedError?.message,
|
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) {
|
if (discordLinks && discordLinks.length > 0) {
|
||||||
console.log(
|
console.log(
|
||||||
`[Email Linking] Found ${discordLinks.length} discord links, transferring...`
|
`[Email Linking] Found ${discordLinks.length} discord links, transferring...`,
|
||||||
);
|
);
|
||||||
for (const link of discordLinks) {
|
for (const link of discordLinks) {
|
||||||
const { data: existing } = await supabase
|
const { data: existing } = await supabase
|
||||||
|
|
@ -145,7 +145,7 @@ export default async (req: Request) => {
|
||||||
|
|
||||||
if (web3Links && web3Links.length > 0) {
|
if (web3Links && web3Links.length > 0) {
|
||||||
console.log(
|
console.log(
|
||||||
`[Email Linking] Found ${web3Links.length} web3 wallets, transferring...`
|
`[Email Linking] Found ${web3Links.length} web3 wallets, transferring...`,
|
||||||
);
|
);
|
||||||
for (const wallet of web3Links) {
|
for (const wallet of web3Links) {
|
||||||
const { data: existing } = await supabase
|
const { data: existing } = await supabase
|
||||||
|
|
@ -172,7 +172,7 @@ export default async (req: Request) => {
|
||||||
|
|
||||||
// Insert primary email
|
// Insert primary email
|
||||||
const primaryEmailExists = existingLinks?.some(
|
const primaryEmailExists = existingLinks?.some(
|
||||||
(l) => l.email === primaryEmail
|
(l) => l.email === primaryEmail,
|
||||||
);
|
);
|
||||||
if (!primaryEmailExists) {
|
if (!primaryEmailExists) {
|
||||||
await supabase.from("user_email_links").insert({
|
await supabase.from("user_email_links").insert({
|
||||||
|
|
@ -185,7 +185,7 @@ export default async (req: Request) => {
|
||||||
|
|
||||||
// Insert linked email
|
// Insert linked email
|
||||||
const linkedEmailExists = existingLinks?.some(
|
const linkedEmailExists = existingLinks?.some(
|
||||||
(l) => l.email === linkedEmail
|
(l) => l.email === linkedEmail,
|
||||||
);
|
);
|
||||||
if (!linkedEmailExists) {
|
if (!linkedEmailExists) {
|
||||||
await supabase.from("user_email_links").insert({
|
await supabase.from("user_email_links").insert({
|
||||||
|
|
@ -230,7 +230,7 @@ export default async (req: Request) => {
|
||||||
{
|
{
|
||||||
status: 200,
|
status: 200,
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.error("[Email Linking Error]", error);
|
console.error("[Email Linking Error]", error);
|
||||||
|
|
@ -242,7 +242,7 @@ export default async (req: Request) => {
|
||||||
{
|
{
|
||||||
status: 500,
|
status: 500,
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -12,10 +12,10 @@ export default async (req: Request) => {
|
||||||
const { email } = await req.json();
|
const { email } = await req.json();
|
||||||
|
|
||||||
if (!email) {
|
if (!email) {
|
||||||
return new Response(
|
return new Response(JSON.stringify({ error: "Email is required" }), {
|
||||||
JSON.stringify({ error: "Email is required" }),
|
status: 400,
|
||||||
{ status: 400, headers: { "Content-Type": "application/json" } }
|
headers: { "Content-Type": "application/json" },
|
||||||
);
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const supabase = getAdminClient();
|
const supabase = getAdminClient();
|
||||||
|
|
@ -34,10 +34,10 @@ export default async (req: Request) => {
|
||||||
|
|
||||||
if (!emailLink) {
|
if (!emailLink) {
|
||||||
// Email is not linked, return the email as-is
|
// Email is not linked, return the email as-is
|
||||||
return new Response(
|
return new Response(JSON.stringify({ primaryEmail: email }), {
|
||||||
JSON.stringify({ primaryEmail: email }),
|
status: 200,
|
||||||
{ status: 200, headers: { "Content-Type": "application/json" } }
|
headers: { "Content-Type": "application/json" },
|
||||||
);
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the primary email for this user
|
// Get the primary email for this user
|
||||||
|
|
@ -50,10 +50,10 @@ export default async (req: Request) => {
|
||||||
if (profileError) {
|
if (profileError) {
|
||||||
console.error("Profile lookup error:", profileError);
|
console.error("Profile lookup error:", profileError);
|
||||||
// If we can't find the profile, return original email
|
// If we can't find the profile, return original email
|
||||||
return new Response(
|
return new Response(JSON.stringify({ primaryEmail: email }), {
|
||||||
JSON.stringify({ primaryEmail: email }),
|
status: 200,
|
||||||
{ status: 200, headers: { "Content-Type": "application/json" } }
|
headers: { "Content-Type": "application/json" },
|
||||||
);
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Response(
|
return new Response(
|
||||||
|
|
@ -62,7 +62,7 @@ export default async (req: Request) => {
|
||||||
linkedFrom: email,
|
linkedFrom: email,
|
||||||
userId: emailLink.user_id,
|
userId: emailLink.user_id,
|
||||||
}),
|
}),
|
||||||
{ status: 200, headers: { "Content-Type": "application/json" } }
|
{ status: 200, headers: { "Content-Type": "application/json" } },
|
||||||
);
|
);
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.error("[Resolve Linked Email Error]", error);
|
console.error("[Resolve Linked Email Error]", error);
|
||||||
|
|
@ -74,7 +74,7 @@ export default async (req: Request) => {
|
||||||
{
|
{
|
||||||
status: 500,
|
status: 500,
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ The email linking system allows users to authenticate with multiple email addres
|
||||||
### Database Tables
|
### Database Tables
|
||||||
|
|
||||||
#### `user_email_links`
|
#### `user_email_links`
|
||||||
|
|
||||||
Links multiple email addresses to a single user account.
|
Links multiple email addresses to a single user account.
|
||||||
|
|
||||||
```sql
|
```sql
|
||||||
|
|
@ -23,6 +24,7 @@ Links multiple email addresses to a single user account.
|
||||||
```
|
```
|
||||||
|
|
||||||
#### `user_profiles` (additions)
|
#### `user_profiles` (additions)
|
||||||
|
|
||||||
```sql
|
```sql
|
||||||
- primary_email: TEXT (the primary email for the account)
|
- primary_email: TEXT (the primary email for the account)
|
||||||
- is_dev_account: BOOLEAN (marks if this is a developer 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.
|
Resolve a linked email to its primary email address.
|
||||||
|
|
||||||
**Request:**
|
**Request:**
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"email": "mrpiglr@gmail.com"
|
"email": "mrpiglr@gmail.com"
|
||||||
|
|
@ -79,6 +82,7 @@ Resolve a linked email to its primary email address.
|
||||||
```
|
```
|
||||||
|
|
||||||
**Response (linked email):**
|
**Response (linked email):**
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"primaryEmail": "mrpiglr@aethex.dev",
|
"primaryEmail": "mrpiglr@aethex.dev",
|
||||||
|
|
@ -88,6 +92,7 @@ Resolve a linked email to its primary email address.
|
||||||
```
|
```
|
||||||
|
|
||||||
**Response (non-linked email):**
|
**Response (non-linked email):**
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"primaryEmail": "some@email.com"
|
"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.
|
Link two existing user accounts by merging one into the other.
|
||||||
|
|
||||||
**Request:**
|
**Request:**
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"primaryEmail": "mrpiglr@aethex.dev",
|
"primaryEmail": "mrpiglr@aethex.dev",
|
||||||
|
|
@ -107,6 +113,7 @@ Link two existing user accounts by merging one into the other.
|
||||||
```
|
```
|
||||||
|
|
||||||
**Response:**
|
**Response:**
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"success": true,
|
"success": true,
|
||||||
|
|
@ -121,6 +128,7 @@ Link two existing user accounts by merging one into the other.
|
||||||
Special endpoint to link the mrpiglr accounts.
|
Special endpoint to link the mrpiglr accounts.
|
||||||
|
|
||||||
**Request:**
|
**Request:**
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
curl -X POST https://aethex.dev/api/user/link-mrpiglr-accounts \
|
curl -X POST https://aethex.dev/api/user/link-mrpiglr-accounts \
|
||||||
-H "Authorization: Bearer mrpiglr-admin-token" \
|
-H "Authorization: Bearer mrpiglr-admin-token" \
|
||||||
|
|
@ -128,6 +136,7 @@ curl -X POST https://aethex.dev/api/user/link-mrpiglr-accounts \
|
||||||
```
|
```
|
||||||
|
|
||||||
**Response:**
|
**Response:**
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"success": true,
|
"success": true,
|
||||||
|
|
@ -168,6 +177,7 @@ When two accounts are merged:
|
||||||
### For Developers (Dev Accounts)
|
### For Developers (Dev Accounts)
|
||||||
|
|
||||||
Developer accounts with `@aethex.dev` email:
|
Developer accounts with `@aethex.dev` email:
|
||||||
|
|
||||||
- `is_dev_account = true`
|
- `is_dev_account = true`
|
||||||
- `primary_email = "@aethex.dev email"`
|
- `primary_email = "@aethex.dev email"`
|
||||||
- Public profile shows work 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`
|
Applied via: `code/supabase/migrations/20250206_add_email_linking.sql`
|
||||||
|
|
||||||
Includes:
|
Includes:
|
||||||
|
|
||||||
- `user_email_links` table with RLS policies
|
- `user_email_links` table with RLS policies
|
||||||
- `get_primary_user_by_email()` function
|
- `get_primary_user_by_email()` function
|
||||||
- Columns on `user_profiles` for dev accounts and primary email
|
- Columns on `user_profiles` for dev accounts and primary email
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue