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

feat: ✨ adding sign up support for new users #114

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions apps/web/app/(app)/dashboard/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use client';

export default function DashboardPage() {
return (
<div className='container mx-auto py-8'>
<h1 className='text-3xl font-bold'>Dashboard</h1>
</div>
);
}
29 changes: 29 additions & 0 deletions apps/web/app/(auth)/auth/callback/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { createClient } from '@ultra-reporter/supabase/server';
import { NextResponse } from 'next/server';

export async function GET(request: Request) {
const { searchParams, origin } = new URL(request.url);
const code = searchParams.get('code');
// if "next" is in param, use it as the redirect URL
const next = searchParams.get('next') ?? '/';

if (code) {
const supabase = await createClient();
const { error } = await supabase.auth.exchangeCodeForSession(code);
if (!error) {
const forwardedHost = request.headers.get('x-forwarded-host'); // original origin before load balancer
const isLocalEnv = process.env.NODE_ENV === 'development';
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`);
}
14 changes: 14 additions & 0 deletions apps/web/app/(auth)/layout.tsx
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}
</>
);
}
97 changes: 97 additions & 0 deletions apps/web/app/(auth)/login/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
'use client';

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';
import { useState } from 'react';

export default function AuthPage() {
const [isLoading, setIsLoading] = useState(false);

const handleAuth = async () => {
setIsLoading(true);
try {
const response = await fetch('/api/auth/login', {
method: 'POST',
});

if (!response.ok) {
throw new Error('Authentication failed');
}

const data = await response.json();

if (data.url) {
window.location.href = data.url;
} else {
throw new Error('No OAuth URL received');
}
} catch (error) {
console.error('Authentication error:', error);
// You might want to show an error message to the user here
} finally {
setIsLoading(false);
}
};

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={handleAuth}
disabled={isLoading}
>
{isLoading && (
<Icons.spinner className='mr-2 h-5 w-5 animate-spin' />
)}
<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>
);
}
48 changes: 48 additions & 0 deletions apps/web/app/api/auth/login/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { logger } from '@ultra-reporter/logger';
import { createClient } from '@ultra-reporter/supabase/server';
import { NextResponse } from 'next/server';

export async function POST(req: Request) {
try {
const supabase = await createClient();
const origin = req.headers.get('origin') || 'http://localhost:3000';

// Get the URL for Google OAuth sign-in
const { data, error } = await supabase.auth.signInWithOAuth({
provider: 'google',
options: {
redirectTo: `${origin}/auth/callback`,
queryParams: {
access_type: 'offline',
prompt: 'consent',
},
scopes: 'email profile',
},
});

if (error) {
logger.error('OAuth initialization failed', { error });
return NextResponse.json(
{ error: 'Failed to start OAuth flow' },
{ status: 500 }
);
}

if (!data.url) {
logger.error('No OAuth URL returned');
return NextResponse.json(
{ error: 'Invalid OAuth configuration' },
{ status: 500 }
);
}

logger.info('OAuth flow initiated', { url: data.url });
return NextResponse.json({ url: data.url }, { status: 200 });
} catch (error) {
logger.error('Unexpected error during OAuth initialization', { error });
return NextResponse.json(
{ error: 'Internal server error' },
{ status: 500 }
);
}
}
20 changes: 20 additions & 0 deletions apps/web/middleware.ts
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)$).*)',
],
};
6 changes: 4 additions & 2 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@
"react-dom": "^19.0"
},
"dependencies": {
"@next/third-parties": "^15.1.2",
"@next/third-parties": "^15.1.3",
"@tanstack/react-table": "^8.20.6",
"@ultra-reporter/analytics": "workspace:*",
"@ultra-reporter/feature-toggle": "workspace:*",
"@ultra-reporter/logger": "workspace:*",
"@ultra-reporter/supabase": "workspace:*",
"@ultra-reporter/ui": "workspace:*",
"@ultra-reporter/utils": "workspace:*",
"lucide-react": "^0.469.0",
"next": "15.1.2"
"next": "15.1.3"
},
"devDependencies": {
"@types/react": "^19.0.2",
Expand Down
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,32 @@
},
"devDependencies": {
"@eslint/compat": "^1.2.4",
"@next/eslint-plugin-next": "^15.1.2",
"@next/eslint-plugin-next": "^15.1.3",
"@release-it-plugins/lerna-changelog": "^7.0.0",
"@stylistic/eslint-plugin-js": "^2.12.1",
"@stylistic/eslint-plugin-ts": "^2.12.1",
"@types/node": "^22.10.2",
"@typescript-eslint/eslint-plugin": "^8.18.1",
"@typescript-eslint/parser": "^8.18.1",
"@types/node": "^22.10.5",
"@typescript-eslint/eslint-plugin": "^8.19.0",
"@typescript-eslint/parser": "^8.19.0",
"@vercel/style-guide": "^6.0.0",
"eslint": "^9.17.0",
"eslint-config-next": "15.1.2",
"eslint-config-next": "15.1.3",
"eslint-config-prettier": "^9.1.0",
"eslint-config-turbo": "2.3.3",
"eslint-plugin-only-warn": "^1.1.0",
"eslint-plugin-prettier": "^5.2.1",
"globals": "^15.14.0",
"husky": "^9.1.7",
"lerna-changelog": "^2.2.0",
"lint-staged": "^15.2.11",
"lint-staged": "^15.3.0",
"prettier": "^3.4.2",
"prettier-plugin-organize-imports": "^4.1.0",
"prettier-plugin-tailwindcss": "^0.6.9",
"release-it": "^17.10.0",
"release-it": "^17.11.0",
"release-it-pnpm": "^4.6.3",
"turbo": "^2.3.3",
"typescript": "^5.7.2",
"typescript-eslint": "^8.18.1"
"typescript-eslint": "^8.19.0"
},
"lint-staged": {
"**/*.{ts,tsx}": [
Expand Down
53 changes: 34 additions & 19 deletions packages/db/src/schema/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,45 @@ generator client {
}

datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
provider = "postgresql"
url = env("DATABASE_URL")
relationMode = "prisma"
}

model User {
id String @id @default(cuid())
user_name String
email String
provider String
model TestResultData {
id String @id @default(cuid())
suite_name String
test_name String
class_name String
method_name String
is_config Boolean
tags String[]
parameters String[]
status String
exception_id String
attachment_id String
started_at DateTime
finished_at DateTime
duration Float

created_at DateTime @default(now())
updated_at DateTime @updatedAt
exception TestException? @relation(fields: [exception_id], references: [id])

LoginSession LoginSession[]
}
attachment TestLog? @relation(fields: [attachment_id], references: [id])

model LoginSession {
id String @id @default(cuid())
user_id String
last_login_at DateTime @default(now())
created_at DateTime @default(now())
updated_at DateTime @updatedAt
@@index([exception_id])
@@index([attachment_id])
}

user User @relation(fields: [user_id], references: [id])
model TestLog {
id String @id @default(cuid())
line String
TestResultData TestResultData[]
}

@@index([user_id])
model TestException {
id String @id @default(cuid())
class_name String
message String
stack_trace String[]
TestResultData TestResultData[]
}
2 changes: 1 addition & 1 deletion packages/feature-toggle/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
"react-dom": "^19.0"
},
"dependencies": {
"flagsmith": "^8.0.1"
"flagsmith": "^8.0.2"
}
}
2 changes: 1 addition & 1 deletion packages/logger/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"lint": "eslint . --max-warnings 0"
},
"dependencies": {
"pino": "^9.5.0"
"pino": "^9.6.0"
},
"devDependencies": {
"@ultra-reporter/typescript-config": "workspace:*"
Expand Down
28 changes: 28 additions & 0 deletions packages/supabase/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "@ultra-reporter/supabase",
"description": "Ultra Reporter Supabase integration",
"version": "0.6.0",
"private": true,
"scripts": {
"lint": "eslint . --max-warnings 0"
},
"exports": {
"./client": "./src/client.ts",
"./server": "./src/server.ts",
"./middleware": "./src/middleware.ts"
},
"devDependencies": {
"@types/react": "^19.0.2",
"@types/react-dom": "^19.0.2",
"@ultra-reporter/typescript-config": "workspace:*"
},
"peerDependencies": {
"react": "^19.0",
"react-dom": "^19.0"
},
"dependencies": {
"@supabase/ssr": "latest",
"@supabase/supabase-js": "latest",
"next": "15.1.3"
}
}
Loading
Loading