Skip to content

Commit

Permalink
removed supabase assets. install appwrite (#125)
Browse files Browse the repository at this point in the history
![Screenshot 2024-04-10 at 7 16
41 PM](https://github.com/LetsGetTechnical/gridiron-survivor/assets/110337114/497c4545-9294-4c97-8441-731b5a69e5b6)
removed from package.json all supabase
removed the storybook assets
removed the supabase.ts files
renamed the folder to appwrite
installed appwrite

---------

Co-authored-by: Shashi Lo <[email protected]>
Co-authored-by: Mike Chen <[email protected]>
  • Loading branch information
3 people authored and Clue355 committed May 1, 2024
1 parent dac1389 commit 906509a
Show file tree
Hide file tree
Showing 14 changed files with 90 additions and 20,470 deletions.
20 changes: 4 additions & 16 deletions app/auth/callback/route.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,8 @@
import { createClient } from '@/utils/supabase/server'
import { NextResponse } from 'next/server'
import { cookies } from 'next/headers'
import { NextResponse } from 'next/server';

export async function GET(request: Request) {
// The `/auth/callback` route is required for the server-side auth flow implemented
// by the Auth Helpers package. It exchanges an auth code for the user's session.
// https://supabase.com/docs/guides/auth/auth-helpers/nextjs#managing-sign-in-with-code-exchange
const requestUrl = new URL(request.url)
const code = requestUrl.searchParams.get('code')
const requestUrl = new URL(request.url);
const code = requestUrl.searchParams.get('code');

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

// URL to redirect to after sign in process completes
return NextResponse.redirect(requestUrl.origin)
return NextResponse.redirect(requestUrl.origin);
}
4 changes: 2 additions & 2 deletions app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ const defaultUrl = process.env.VERCEL_URL

export const metadata = {
metadataBase: new URL(defaultUrl),
title: 'Next.js and Supabase Starter Kit',
description: 'The fastest way to build apps with Next.js and Supabase',
title: 'Next.js and Appwrite',
description: 'The fastest way to build apps with Next.js and Appwrite'
}

export default function RootLayout({
Expand Down
114 changes: 5 additions & 109 deletions app/login/page.tsx
Original file line number Diff line number Diff line change
@@ -1,118 +1,14 @@
import Link from 'next/link'
import { headers, cookies } from 'next/headers'
import { createClient } from '@/utils/supabase/server'
import { redirect } from 'next/navigation'
import Link from 'next/link';
import { redirect } from 'next/navigation';

export default function Login({
searchParams,
}: {
searchParams: { message: string }
searchParams: { message: string };
}) {
const signIn = async (formData: FormData) => {
'use server'

const email = formData.get('email') as string
const password = formData.get('password') as string
const cookieStore = cookies()
const supabase = createClient(cookieStore)

const { error } = await supabase.auth.signInWithPassword({
email,
password,
})

if (error) {
return redirect('/login?message=Could not authenticate user')
}

return redirect('/')
}

const signUp = async (formData: FormData) => {
'use server'

const origin = headers().get('origin')
const email = formData.get('email') as string
const password = formData.get('password') as string
const cookieStore = cookies()
const supabase = createClient(cookieStore)

const { error } = await supabase.auth.signUp({
email,
password,
options: {
emailRedirectTo: `${origin}/auth/callback`,
},
})

if (error) {
return redirect('/login?message=Could not authenticate user')
}

return redirect('/login?message=Check email to continue sign in process')
}

return (
<div className="flex-1 flex flex-col w-full px-8 sm:max-w-md justify-center gap-2">
<Link
href="/"
className="absolute left-8 top-8 py-2 px-4 rounded-md no-underline text-foreground bg-btn-background hover:bg-btn-background-hover flex items-center group text-sm"
>
<svg
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
strokeLinejoin="round"
className="mr-2 h-4 w-4 transition-transform group-hover:-translate-x-1"
>
<polyline points="15 18 9 12 15 6" />
</svg>{' '}
Back
</Link>

<form
className="animate-in flex-1 flex flex-col w-full justify-center gap-2 text-foreground"
action={signIn}
>
<label className="text-md" htmlFor="email">
Email
</label>
<input
className="rounded-md px-4 py-2 bg-inherit border mb-6"
name="email"
placeholder="[email protected]"
required
/>
<label className="text-md" htmlFor="password">
Password
</label>
<input
className="rounded-md px-4 py-2 bg-inherit border mb-6"
type="password"
name="password"
placeholder="••••••••"
required
/>
<button className="bg-green-700 rounded-md px-4 py-2 text-foreground mb-2">
Sign In
</button>
<button
formAction={signUp}
className="border border-foreground/20 rounded-md px-4 py-2 text-foreground mb-2"
>
Sign Up
</button>
{searchParams?.message && (
<p className="mt-4 p-4 bg-foreground/10 text-foreground text-center">
{searchParams.message}
</p>
)}
</form>
<h1 className="text-2xl font-bold text-center text-foreground">Hello GIS</h1>
</div>
)
);
}
43 changes: 6 additions & 37 deletions app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,43 +1,12 @@
import AuthButton from '../components/AuthButton'
import { createClient } from '@/utils/supabase/server'
import { cookies } from 'next/headers'

export default async function Index() {
const cookieStore = cookies()

const canInitSupabaseClient = () => {
// This function is just for the interactive tutorial.
// Feel free to remove it once you have Supabase connected.
try {
createClient(cookieStore)
return true
} catch (e) {
return false
}
}

const isSupabaseConnected = canInitSupabaseClient()
import AuthButton from '../components/AuthButton';

export default function Index() {
return (
<div
className={[
'flex flex-col items-center justify-center flex-1',
'w-full',
].join(' ')}
>
<nav
className={[
'flex flex-col items-center justify-center flex-1',
'w-full',
].join(' ')}
>
<div className="flex flex-col items-center justify-center flex-1 w-full">
<nav className="flex flex-col items-center justify-center flex-1 w-full">
<p>Gridiron Survivor</p>
{isSupabaseConnected ? (
<AuthButton />
) : (
'Unable to connect to authentication server. Please try again later.'
)}
<AuthButton />
</nav>
</div>
)
);
}
38 changes: 14 additions & 24 deletions components/AuthButton.tsx
Original file line number Diff line number Diff line change
@@ -1,40 +1,30 @@
import { createClient } from '@/utils/supabase/server'
import Link from 'next/link'
import { cookies } from 'next/headers'
import { redirect } from 'next/navigation'
import Link from 'next/link';
import { cookies } from 'next/headers';
import { redirect } from 'next/navigation';

export default async function AuthButton() {
const cookieStore = cookies()
const supabase = createClient(cookieStore)

const {
data: { user },
} = await supabase.auth.getUser()
const cookieStore = cookies();
// Assume user is always logged in for demonstration purposes
const user = { email: '[email protected]' };

const signOut = async () => {
'use server'

const cookieStore = cookies()
const supabase = createClient(cookieStore)
await supabase.auth.signOut()
return redirect('/login')
}
// Perform sign out logic here
// For example, clear cookies or session variables
return redirect('/login');
};

return user ? (
<div className="flex items-center gap-4">
Hey, {user.email}!
<form action={signOut}>
<button className="py-2 px-4 rounded-md no-underline bg-btn-background hover:bg-btn-background-hover">
<form onSubmit={signOut}>
<button type="submit" className="py-2 px-4 rounded-md no-underline bg-btn-background hover:bg-btn-background-hover">
Logout
</button>
</form>
</div>
) : (
<Link
href="/login"
className="py-2 px-3 flex rounded-md no-underline bg-btn-background hover:bg-btn-background-hover"
>
<Link href="/login" className="py-2 px-3 flex rounded-md no-underline bg-btn-background hover:bg-btn-background-hover">
Login
</Link>
)
);
}
19 changes: 6 additions & 13 deletions middleware.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
import { NextResponse, type NextRequest } from 'next/server'
import { createClient } from '@/utils/supabase/middleware'

export async function middleware(request: NextRequest) {
try {
// This `try/catch` block is only here for the interactive tutorial.
// Feel free to remove once you have Supabase connected.
const { supabase, response } = createClient(request)

// Refresh session if expired - required for Server Components
// https://supabase.com/docs/guides/auth/auth-helpers/nextjs#managing-session-with-middleware
await supabase.auth.getSession()

return response
return NextResponse.next({
request: {
headers: request.headers,
},
})
} catch (e) {
// If you are here, a Supabase client could not be created!
// This is likely because you have not set up environment variables.
// Check out http://localhost:3000 for Next Steps.

return NextResponse.next({
request: {
headers: request.headers,
Expand Down
Loading

0 comments on commit 906509a

Please sign in to comment.