-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from devzero-inc/local-supabase
completes the app functionality
- Loading branch information
Showing
24 changed files
with
2,169 additions
and
81 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,39 @@ | ||
name: Roadmap Voting App CI | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
paths: | ||
- 'roadmap-voting-app/**' | ||
pull_request: | ||
branches: [ main ] | ||
paths: | ||
- 'roadmap-voting-app/**' | ||
|
||
jobs: | ||
build-and-test: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Node.js | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: '20.x' | ||
|
||
- name: Install Dependencies | ||
run: | | ||
cd roadmap-voting-app | ||
npm install | ||
# - name: Lint | ||
# run: | | ||
# cd roadmap-voting-app | ||
# npm run lint | ||
|
||
# - name: Run Tests | ||
# run: | | ||
# cd roadmap-voting-app | ||
# npm test |
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,3 @@ | ||
{ | ||
"recommendations": ["denoland.vscode-deno"] | ||
} |
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,10 @@ | ||
{ | ||
"deno.enablePaths": [ | ||
"supabase/functions" | ||
], | ||
"deno.lint": true, | ||
"deno.unstable": true, | ||
"[typescript]": { | ||
"editor.defaultFormatter": "denoland.vscode-deno" | ||
} | ||
} |
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,30 @@ | ||
import { NextRequest, NextResponse } from 'next/server'; | ||
import { supabase } from '../../../lib/supabaseClient'; | ||
|
||
export async function GET(req: NextRequest) { | ||
try { | ||
|
||
const postId = req.nextUrl.searchParams.get("postId"); | ||
|
||
if (postId) { | ||
const { data, error } = await supabase | ||
.from('votes') | ||
.select('*') | ||
.eq('postid', postId); | ||
|
||
if (error) throw error; | ||
return NextResponse.json({ votes: data, status: 200 }); | ||
}else{ | ||
const { data, error } = await supabase.from('posts').select('*'); | ||
|
||
if (error) throw error; | ||
return NextResponse.json({ posts: data, status: 200 }); | ||
} | ||
} catch (error) { | ||
if (error) { | ||
return NextResponse.json({ message: error, status: 401 }); | ||
} else { | ||
return NextResponse.json({ message: 'An unexpected error occurred', status: 500 }); | ||
} | ||
} | ||
} |
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,59 @@ | ||
import { NextRequest, NextResponse } from 'next/server'; | ||
import { supabase } from '../../../lib/supabaseClient'; | ||
import { v4 as uuidv4 } from 'uuid'; | ||
import {authenticate} from '../../../lib/authenticate'; | ||
|
||
export async function POST(req: NextRequest) { | ||
try { | ||
const user = await authenticate(req); | ||
|
||
const formdata = await req.formData(); | ||
const postId = formdata.get("postId") as string; | ||
const userId = formdata.get("userId") as string; | ||
const type = formdata.get("type") as string; | ||
|
||
if (!postId || !userId) { | ||
return NextResponse.json({ message: 'Post ID and User ID are required', status: 400 }); | ||
} | ||
if (!type) { | ||
return NextResponse.json({ message: 'Vote type is required', status: 400 }); | ||
} | ||
|
||
const existingVote = await supabase | ||
.from('votes') | ||
.select('*') | ||
.eq('postid', postId) | ||
.eq('userid', userId) | ||
.single(); | ||
|
||
if (existingVote.data) { | ||
const response = await supabase | ||
.from('votes') | ||
.update({ type, updatedAt: new Date() }) | ||
.eq('postid', postId) | ||
.eq('userid', userId); | ||
if (response.error){ | ||
throw response.error; | ||
} | ||
|
||
return NextResponse.json({ message: "Vote updated successfully", status: 201 }); | ||
}else{ | ||
const date = new Date(); | ||
const id = uuidv4(); | ||
const response = await supabase | ||
.from('votes') | ||
.insert([{ id: id, postid: postId, userid: userId, type: type }]); | ||
if (response.error){ | ||
throw response.error; | ||
} | ||
return NextResponse.json({ message: "Vote recorded successfully", data: {id: id, postId: postId, userId: userId, type: type, createdAt: date, updatedAt: date }, status: 200 }); | ||
} | ||
} catch (error) { | ||
console.log(error); | ||
if (error) { | ||
return NextResponse.json({ message: error, status: 401 }); | ||
} else { | ||
return NextResponse.json({ message: 'An unexpected error occurred', status: 500 }); | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,21 +1,51 @@ | ||
"use client"; | ||
|
||
import Link from "next/link"; | ||
import { useState } from "react"; | ||
import { useRouter } from "next/navigation"; | ||
|
||
const SignIn = () => { | ||
|
||
const router = useRouter(); | ||
const [email, setEmail] = useState<string>(""); | ||
const [password, setPassword] = useState<string>(""); | ||
|
||
const handleSignin = (e: React.FormEvent<HTMLFormElement>) => { | ||
e.preventDefault(); | ||
|
||
const newFormData = new FormData(); | ||
newFormData.append("email", email); | ||
newFormData.append("password", password); | ||
|
||
fetch("/api/user?login=yes", { | ||
method: "POST", | ||
body: newFormData | ||
}) | ||
.then(res => res.json()) | ||
.then(data => { | ||
localStorage.setItem("session", JSON.stringify(data.data.session)); | ||
localStorage.setItem("name", data.userData.name); | ||
window.dispatchEvent(new Event("storageUpdate")); | ||
router.push('/'); | ||
}) | ||
.catch(err => console.log(err)); | ||
} | ||
|
||
const Signup = () => { | ||
return ( | ||
<div className=" bg-cusSec border border-cusBorder flex-1 w-[50%] mb-5 rounded-lg text-white p-4 flex flex-col items-center justify-around"> | ||
<h1 className=" text-6xl font-bold bg-clip-text text-transparent bg-custom-gradient p-2">Sign In</h1> | ||
<form className="flex flex-col gap-4"> | ||
<input className=" px-4 py-3 rounded-lg bg-cusInput outline-none" type="email" placeholder="Enter your email"/> | ||
<input className=" px-4 py-3 rounded-lg bg-cusInput outline-none" type="password" placeholder="Enter your password"/> | ||
<form className="flex flex-col gap-4" onSubmit={handleSignin}> | ||
<input className=" px-4 py-3 rounded-lg bg-cusInput outline-none" type="email" placeholder="Enter your email" onChange={e => setEmail(e.target.value)} /> | ||
<input className=" px-4 py-3 rounded-lg bg-cusInput outline-none" type="password" placeholder="Enter your password" onChange={e => setPassword(e.target.value)} /> | ||
<Link href="/auth/signup" className="outline-none text-center"> | ||
Don't have an account? <span className="bg-clip-text text-transparent bg-custom-gradient">Signup</span> | ||
</Link> | ||
<button className=" bg-custom-gradient px-4 py-3 rounded-lg outline-none"> | ||
<button type="submit" className=" bg-custom-gradient px-4 py-3 rounded-lg outline-none"> | ||
Sign In | ||
</button> | ||
</form> | ||
</div> | ||
) | ||
} | ||
|
||
export default Signup | ||
export default SignIn |
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
Oops, something went wrong.