-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
manading form_create from falling down and allowing user to create ta…
…ble if their no entries for them in users table
- Loading branch information
1 parent
58621aa
commit 4926a31
Showing
18 changed files
with
596 additions
and
106 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,10 @@ | ||
import {NextRequest, NextResponse} from "next/server"; | ||
import {createClient} from "@/utils/supabase/server"; | ||
|
||
export async function GET(req: NextRequest) { | ||
const supabase = createClient() | ||
|
||
const { error } = await supabase.auth.signOut() | ||
|
||
return NextResponse.redirect(new URL("/form_create", req.url)) | ||
} |
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,29 @@ | ||
import {NextRequest, NextResponse} from "next/server"; | ||
|
||
export async function POST(req: NextRequest) { | ||
let response = NextResponse.next({ | ||
request: { | ||
headers: req.headers, | ||
}, | ||
}) | ||
|
||
const body = await req.json() | ||
|
||
if ( !body.username ) { | ||
return NextResponse.json({ error: 'username is required' }) | ||
} | ||
|
||
let res = await fetch(`${process.env.NEXT_PUBLIC_SUPABASE_URL}/rest/v1/rpc/is_username_exist`, { | ||
method: 'POST', | ||
headers: { | ||
"apikey": process.env.SERVICE_KEY!, | ||
"Authorization": `Bearer ${process.env.SERVICE_KEY!}`, | ||
"Content-Type": "application/json", | ||
}, | ||
body: JSON.stringify(body) | ||
}); | ||
|
||
let data = await res.json(); | ||
|
||
return NextResponse.json({ state: data }); | ||
} |
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 @@ | ||
import {NextRequest, NextResponse} from "next/server"; | ||
import { createClient } from "@/utils/supabase/server"; | ||
import { User } from "@supabase/supabase-js"; | ||
|
||
export async function POST(req: NextRequest) { | ||
let response = NextResponse.next({ | ||
request: { | ||
headers: req.headers, | ||
}, | ||
}) | ||
|
||
const body = await req.json() | ||
const supabase = createClient(); | ||
const searchParams = req.nextUrl.searchParams; | ||
const option = searchParams.get('option'); | ||
|
||
let data: User | User[] | null = null; | ||
|
||
if ( option === 'insert' ) { | ||
const { data: user, error: error } = await supabase | ||
.from('users') | ||
.insert([{id: body.id, username: body.username, admin: body.admin}]) | ||
if (error) { | ||
return NextResponse.json({ error: error.message }, { status: 500 }); | ||
} | ||
data = user; | ||
} else if ( option === 'update' ) { | ||
const { data: user, error: error } = await supabase | ||
.from('users') | ||
.update({username: body.username}) | ||
.match({id: body.id}) | ||
if (error) { | ||
return NextResponse.json({ error: error.message }, { status: 500 }); | ||
} | ||
data = user; | ||
} | ||
|
||
return NextResponse.json({ data: data }); | ||
} |
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.