-
-
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
- Loading branch information
Showing
12 changed files
with
891 additions
and
214 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
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
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" | ||
} | ||
} |
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,8 @@ | ||
import { createBrowserClient } from '@supabase/ssr'; | ||
|
||
export function createClient() { | ||
return createBrowserClient( | ||
process.env.NEXT_PUBLIC_SUPABASE_URL!, | ||
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY! | ||
); | ||
} |
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,53 @@ | ||
import { createServerClient } from '@supabase/ssr'; | ||
import { type NextRequest, NextResponse } from 'next/server'; | ||
|
||
export const updateSession = async (request: NextRequest) => { | ||
try { | ||
let response = NextResponse.next({ | ||
request: { | ||
headers: request.headers, | ||
}, | ||
}); | ||
|
||
const supabase = createServerClient( | ||
process.env.NEXT_PUBLIC_SUPABASE_URL!, | ||
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!, | ||
{ | ||
cookies: { | ||
getAll() { | ||
return request.cookies.getAll(); | ||
}, | ||
setAll(cookiesToSet) { | ||
cookiesToSet.forEach(({ name, value }) => | ||
request.cookies.set(name, value) | ||
); | ||
response = NextResponse.next({ | ||
request, | ||
}); | ||
cookiesToSet.forEach(({ name, value, options }) => | ||
response.cookies.set(name, value, options) | ||
); | ||
}, | ||
}, | ||
} | ||
); | ||
|
||
const user = await supabase.auth.getUser(); | ||
|
||
if (request.nextUrl.pathname.startsWith('/protected') && user.error) { | ||
return NextResponse.redirect(new URL('/sign-in', request.url)); | ||
} | ||
|
||
if (request.nextUrl.pathname === '/' && !user.error) { | ||
return NextResponse.redirect(new URL('/protected', request.url)); | ||
} | ||
|
||
return response; | ||
} catch (e) { | ||
return NextResponse.next({ | ||
request: { | ||
headers: request.headers, | ||
}, | ||
}); | ||
} | ||
}; |
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 { createServerClient } from '@supabase/ssr'; | ||
import { cookies } from 'next/headers'; | ||
|
||
export const createClient = async () => { | ||
const cookieStore = await cookies(); | ||
|
||
return createServerClient( | ||
process.env.NEXT_PUBLIC_SUPABASE_URL!, | ||
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!, | ||
{ | ||
cookies: { | ||
getAll() { | ||
return cookieStore.getAll(); | ||
}, | ||
setAll(cookiesToSet) { | ||
try { | ||
cookiesToSet.forEach(({ name, value, options }) => { | ||
cookieStore.set(name, value, options); | ||
}); | ||
} catch (error) { | ||
// The `set` method was called from a Server Component. | ||
// This can be ignored if you have middleware refreshing | ||
// user sessions. | ||
} | ||
}, | ||
}, | ||
} | ||
); | ||
}; |
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,11 @@ | ||
{ | ||
"extends": "@ultra-reporter/typescript-config/nextjs.json", | ||
"compilerOptions": { | ||
"baseUrl": ".", | ||
"paths": { | ||
"@/*": ["./src/*"] | ||
} | ||
}, | ||
"include": ["src"], | ||
"exclude": ["node_modules"] | ||
} |
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.