Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

little changes to api/isUsername #77

Merged
merged 13 commits into from
Jul 30, 2024
160 changes: 159 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"@emotion/styled": "^11.12.0",
"@mui/material": "^5.16.4",
"@radix-ui/react-avatar": "^1.1.0",
"@radix-ui/react-checkbox": "^1.1.1",
"@radix-ui/react-dialog": "^1.1.1",
"@radix-ui/react-dropdown-menu": "^2.1.1",
"@radix-ui/react-icons": "^1.3.0",
Expand Down
Binary file added public/home/homebg.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/home/placeholder.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 18 additions & 22 deletions src/app/api/rest/v1/isUsername/route.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,25 @@
import {NextRequest, NextResponse} from "next/server";
import { createClient } from "@/utils/supabase/server";

export async function POST(req: NextRequest): Promise<NextResponse> {
let response = NextResponse.next({
request: {
headers: req.headers,
},
})
try {
const supabase = createClient();
const body = await req.json();
if (!body.username) {
return NextResponse.json({ error: 'username is required' }, { status: 400 });
}

const body = await req.json()
const { data, error } = await supabase
.rpc('is_username_exist',
{ username: body.username }
);

if ( !body.username ) {
return NextResponse.json({ error: 'username is required' })
}
if (error) {
return NextResponse.json({ error: error.message }, { status: 500 });
}

let res = await fetch(`${process.env.NEXT_PUBLIC_SUPABASE_URL}/rest/v1/rpc/is_username_exist`, {
method: 'POST',
headers: {
"apikey": process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
"Authorization": `Bearer ${process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!}`,
"Content-Type": "application/json",
},
body: JSON.stringify(body)
});

let data = await res.json();

return NextResponse.json({ state: data });
return NextResponse.json({ state: data }, { status: 200 });
} catch (error: any) {
return NextResponse.json({ error: error.message }, { status: 500 });
}
}
19 changes: 19 additions & 0 deletions src/app/api/update-password/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import {NextRequest, NextResponse} from "next/server";
import { cookies } from 'next/headers';
import {createClient} from "@/utils/supabase/server";

export async function GET(req: NextRequest) {
const requestUrl = new URL(req.nextUrl.href)
const code = requestUrl.searchParams.get('code')

if( code ) {
const supabase = createClient()
const { error } = await supabase.auth.exchangeCodeForSession(code)

return NextResponse.redirect(new URL(`${req.nextUrl.origin}/auth/update_password`, req.nextUrl.href))
}

console.log({error : 'ERROR: Invalid auth code or no auth code found'}, { status: 500 })

return NextResponse.redirect(new URL(`${req.nextUrl.origin}/auth`, req.nextUrl.href))
}
23 changes: 23 additions & 0 deletions src/app/auth/component/component.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import React, { FormEvent, use, useEffect, useState } from "react";
import Link from "next/link";
import axios from "axios";

import { Label } from "@/components/ui/label"
import { Input } from "@/components/ui/input"
import { Button } from "@/components/ui/button"
import { Checkbox } from "@/components/ui/checkbox"
import Loader from '@/components/ui/loader'

import { VscEye, VscEyeClosed } from "react-icons/vsc"
Expand Down Expand Up @@ -165,6 +167,27 @@ export function Component( props : Props) {
<i className={`${!(input.name === 'password') && 'hidden'} ${styles.inputicon} ${styles.eyeicon}`} onClick={() => setRevealPassword(!revealPassword)}>{revealPassword?<VscEyeClosed size='23px'/>:<VscEye size='23px'/>}</i>
</div>
))}

{auth === 'login' &&
<div className="flex items-center justify-between">
<div className="flex items-center">
<Checkbox
id="remember-me"
name="remember-me"
className="h-4 w-4 rounded text-primary focus:ring-primary"
checked
disabled
/>
<Label htmlFor="remember-me" className="ml-2 block text-sm text-foreground">
Remember me
</Label>
</div>
<div className="text-sm">
<Link href="auth/reset_password" className="font-medium text-primary hover:text-primary/80" prefetch={false}>
Forgot your password?
</Link>
</div>
</div>}
<div>
<Button
type="submit"
Expand Down
5 changes: 5 additions & 0 deletions src/app/auth/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ export default function Auth(){
</div>)}

{oauthhidden && <OAuthComponent onClick={Authsignin} />}
<div className="text-center text-sm text-muted-foreground">
<Link href="/home" className="font-medium hover:underline" prefetch={false}>
Back to Home
</Link>
</div>
</Component>
</Suspense>
)
Expand Down
Loading
Loading