-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ✨ adding sign up support for new users (#114)
* feat: ✨ adding sign up support for new users * fix: 🐛 fixed issue with sign up api * feat: ✨ adding sign in feature for new users * fix: 🐛 fixed lint issues * fix: 🐛 fixed issue with google sign in * fix: 🐛 fixed issue with lint workflow * perf: 🔊 added debug logs * perf: 🔊 added preview debug logs * perf: 🔊 updated preview debug logs * feat: ✨ handled redirects for different envs for login * fix: 🐛 fixed issue with login on preview instance * fix: 🐛 fixed issue when sign in feature is off
- Loading branch information
Showing
31 changed files
with
3,026 additions
and
1,579 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,15 @@ | ||
'use client'; | ||
|
||
import { signOut } from '@/app/utils/actions'; | ||
import { Button } from '@ultra-reporter/ui/components/button'; | ||
|
||
export default function DashboardPage() { | ||
return ( | ||
<div className='container mx-auto py-8'> | ||
<h1 className='text-3xl font-bold'>Dashboard</h1> | ||
<Button onClick={signOut} variant='default' size='lg' className='mt-4'> | ||
Sign Out | ||
</Button> | ||
</div> | ||
); | ||
} |
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,46 @@ | ||
import { logger } from '@ultra-reporter/logger'; | ||
import { createClient } from '@ultra-reporter/supabase/server'; | ||
import { isPreview } from '@ultra-reporter/utils/constants'; | ||
import { NextResponse } from 'next/server'; | ||
|
||
export async function GET(request: Request) { | ||
const { searchParams, origin } = new URL(request.url); | ||
const code = searchParams.get('code'); | ||
const next = searchParams.get('next') ?? '/dashboard'; | ||
|
||
if (isPreview) { | ||
logger.debug('===================='); | ||
logger.debug(`Route Received URL: ${request.url}`); | ||
logger.debug(`Route Received searchParams: ${searchParams}`); | ||
logger.debug(`Route Received code: ${code}`); | ||
logger.debug(`Route Received next: ${next}`); | ||
logger.debug(`Route Received origin: ${origin}`); | ||
logger.debug('===================='); | ||
} | ||
|
||
if (code) { | ||
const supabase = await createClient(); | ||
const { error } = await supabase.auth.exchangeCodeForSession(code); | ||
if (!error) { | ||
const forwardedHost = request.headers.get('x-forwarded-host'); | ||
const isLocalEnv = process.env.NODE_ENV === 'development'; | ||
if (isPreview) { | ||
logger.debug('===================='); | ||
logger.debug(`Route Received forwardedHost: ${forwardedHost}`); | ||
logger.debug(`Route Received isLocalEnv: ${isLocalEnv}`); | ||
logger.debug('===================='); | ||
} | ||
if (isLocalEnv) { | ||
// we can be sure that there is no load balancer in between, so no need to watch for X-Forwarded-Host | ||
return NextResponse.redirect(`${origin}${next}`); | ||
} else if (forwardedHost) { | ||
return NextResponse.redirect(`https://${forwardedHost}${next}`); | ||
} else { | ||
return NextResponse.redirect(`${origin}${next}`); | ||
} | ||
} | ||
} | ||
|
||
// return the user to an error page with instructions | ||
return NextResponse.redirect(`${origin}/auth/auth-code-error`); | ||
} |
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,14 @@ | ||
import { NavBar } from '@ultra-reporter/ui/home/nav-bar'; | ||
|
||
export default function AuthLayout({ | ||
children, | ||
}: { | ||
children: React.ReactNode; | ||
}) { | ||
return ( | ||
<> | ||
<NavBar hideAuth={true} /> | ||
{children} | ||
</> | ||
); | ||
} |
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,65 @@ | ||
'use client'; | ||
|
||
import { signinWithGoogle } from '@/app/utils/actions'; | ||
import { Button } from '@ultra-reporter/ui/components/button'; | ||
import { DemoCarousel } from '@ultra-reporter/ui/components/demo-carousel'; | ||
import { Icons } from '@ultra-reporter/ui/components/icons'; | ||
|
||
export default function AuthPage() { | ||
return ( | ||
<div className='container mx-auto flex min-h-screen items-center justify-center'> | ||
<div className='grid w-full items-center gap-8 lg:grid-cols-2'> | ||
{/* Demo Carousel Section */} | ||
<div className='relative hidden h-[600px] lg:block'> | ||
<DemoCarousel /> | ||
</div> | ||
|
||
{/* Auth Section */} | ||
<div className='mx-auto w-full max-w-md space-y-8'> | ||
<div className='space-y-2 text-center'> | ||
<h1 className='text-3xl font-bold tracking-tight'> | ||
Welcome to Ultra Reporter | ||
</h1> | ||
<p className='text-muted-foreground text-lg'> | ||
Sign in to your account or create a new one | ||
</p> | ||
</div> | ||
|
||
<div className='space-y-4'> | ||
<Button | ||
variant='default' | ||
size='lg' | ||
className='w-full py-6 text-lg' | ||
onClick={signinWithGoogle} | ||
> | ||
<Icons.google className='mr-2 h-5 w-5' /> | ||
Continue with Google | ||
</Button> | ||
|
||
<div className='relative'> | ||
<div className='absolute inset-0 flex items-center'> | ||
<span className='w-full border-t' /> | ||
</div> | ||
<div className='relative flex justify-center text-sm uppercase'> | ||
<span className='bg-background text-muted-foreground px-2'> | ||
Secure Authentication | ||
</span> | ||
</div> | ||
</div> | ||
|
||
<p className='text-muted-foreground text-center text-sm'> | ||
By continuing, you agree to our{' '} | ||
<a href='/terms' className='hover:text-primary underline'> | ||
Terms of Service | ||
</a>{' '} | ||
and{' '} | ||
<a href='/privacy' className='hover:text-primary underline'> | ||
Privacy Policy | ||
</a> | ||
</p> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} |
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,69 @@ | ||
'use server'; | ||
|
||
import { logger } from '@ultra-reporter/logger'; | ||
import { Provider } from '@ultra-reporter/supabase/client'; | ||
import { createClient } from '@ultra-reporter/supabase/server'; | ||
import { isPreview, isProd } from '@ultra-reporter/utils/constants'; | ||
import { headers } from 'next/headers'; | ||
import { redirect } from 'next/navigation'; | ||
|
||
const getURL = () => { | ||
let url = isProd | ||
? process?.env?.NEXT_PUBLIC_SITE_URL | ||
: isPreview | ||
? process?.env?.NEXT_PUBLIC_VERCEL_URL | ||
: 'http://localhost:3000/'; | ||
// Make sure to include `https://` when not localhost. | ||
url = url?.startsWith('http') ? url : `https://${url}`; | ||
// Make sure to include a trailing `/`. | ||
url = url.endsWith('/') ? url : `${url}/`; | ||
return url; | ||
}; | ||
|
||
const signInWith = (provider: Provider) => async () => { | ||
const supabase = await createClient(); | ||
const requestHeaders = await headers(); | ||
const origin = getURL(); | ||
|
||
if (isPreview) { | ||
logger.debug('===================='); | ||
logger.debug(`Actions Received provider: ${provider}`); | ||
logger.debug(`Actions Received origin: ${origin}`); | ||
requestHeaders.forEach((key, value) => { | ||
logger.debug(`Actions Header [${key}]: [${value}]`); | ||
}); | ||
logger.debug('===================='); | ||
} | ||
|
||
const { data, error } = await supabase.auth.signInWithOAuth({ | ||
provider: provider, | ||
options: { | ||
redirectTo: `${origin}auth/callback`, | ||
}, | ||
}); | ||
|
||
if (error) { | ||
logger.error(`Error while signing in with ${provider}: ${error.message}`); | ||
} | ||
if (data?.url) { | ||
if (isPreview) { | ||
logger.debug(`Actions Redirecting to: ${data.url}`); | ||
} | ||
redirect(data.url); | ||
} | ||
}; | ||
|
||
const signinWithGoogle = signInWith('google'); | ||
|
||
const signOut = async () => { | ||
const supabase = await createClient(); | ||
const { error } = await supabase.auth.signOut(); | ||
|
||
if (!error) { | ||
redirect('/'); | ||
} else { | ||
logger.error(`Error while signing out: ${error.message}`); | ||
} | ||
}; | ||
|
||
export { signinWithGoogle, signOut }; |
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,20 @@ | ||
import { updateSession } from '@ultra-reporter/supabase/middleware'; | ||
import { type NextRequest } from 'next/server'; | ||
|
||
export async function middleware(request: NextRequest) { | ||
return await updateSession(request); | ||
} | ||
|
||
export const config = { | ||
matcher: [ | ||
/* | ||
* Match all request paths except: | ||
* - _next/static (static files) | ||
* - _next/image (image optimization files) | ||
* - favicon.ico (favicon file) | ||
* - images - .svg, .png, .jpg, .jpeg, .gif, .webp | ||
* Feel free to modify this pattern to include more paths. | ||
*/ | ||
'/((?!_next/static|_next/image|favicon.ico|.*\\.(?:svg|png|jpg|jpeg|gif|webp)$).*)', | ||
], | ||
}; |
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.