The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
chore: remove auth0
phamhieuc954b5e4ea69
diff --git a/studio/components/interfaces/Home/Landing.tsx b/studio/components/interfaces/Home/Landing.tsxindex ec00c7236b0..f1a9986f9fe 100644--- a/studio/components/interfaces/Home/Landing.tsx+++ b/studio/components/interfaces/Home/Landing.tsx@@ -4,9 +4,8 @@ import Head from 'next/head'import { observer } from 'mobx-react-lite'import { Button, IconGitHub, Typography } from '@supabase/ui'-import { API_URL } from 'lib/constants'import { useStore } from 'hooks'-import { auth, GOTRUE_ENABLED } from 'lib/gotrue'+import { auth } from 'lib/gotrue'const Landing = () => {const { ui } = useStore()@@ -55,13 +54,9 @@ const Landing = () => {type="success"className="ml-8 font-medium hover:text-gray-300 focus:outline-none focus:text-gray-300 transition duration-150 ease-in-out">- {GOTRUE_ENABLED ? (- <Button onClick={handleGithubSignIn} icon={<IconGitHub />}>- Sign In With Github- </Button>- ) : (- <Link href={`${API_URL}/login`}>Sign In</Link>- )}+ <Button onClick={handleGithubSignIn} icon={<IconGitHub />}>+ Sign In With Github+ </Button></Typography.Text></div></nav>@@ -78,15 +73,9 @@ const Landing = () => {</p></Typography.Text><div className="mt-5 sm:mt-8 sm:flex sm:justify-center space-x-3">- {GOTRUE_ENABLED ? (- <Button onClick={handleGithubSignIn} size="large" icon={<IconGitHub />}>- Sign In With Github- </Button>- ) : (- <Link href={`${API_URL}/login`}>- <Button size="large">Sign In</Button>- </Link>- )}+ <Button onClick={handleGithubSignIn} size="large" icon={<IconGitHub />}>+ Sign In With Github+ </Button><Link href="https://supabase.com/docs"><Button size="large" type="default">Docsdiff --git a/studio/components/layouts/AccountLayout/AccountLayout.tsx b/studio/components/layouts/AccountLayout/AccountLayout.tsxindex 48bf14c7900..3099c8e54b4 100644--- a/studio/components/layouts/AccountLayout/AccountLayout.tsx+++ b/studio/components/layouts/AccountLayout/AccountLayout.tsx@@ -5,7 +5,7 @@ import { observer } from 'mobx-react-lite'import { API_URL, IS_PLATFORM } from 'lib/constants'import { useStore } from 'hooks'import WithSidebar from './WithSidebar'-import { auth, GOTRUE_ENABLED } from 'lib/gotrue'+import { auth } from 'lib/gotrue'/*** layout for dashboard homepage, account and org settings@@ -25,16 +25,14 @@ const AccountLayout = ({ children, title, breadcrumbs }: any) => {router.reload()}- let baseLogoutLink = {+ const baseLogoutLink = {icon: '/icons/feather/power.svg',label: 'Logout',href: `${API_URL}/logout`,key: `${API_URL}/logout`,}- let logoutLink = GOTRUE_ENABLED- ? { ...baseLogoutLink, href: undefined, onClick: onClickLogout }- : baseLogoutLink+ const logoutLink = { ...baseLogoutLink, href: undefined, onClick: onClickLogout }const organizationsLinks = app.organizations.list()diff --git a/studio/lib/api/apiAuthenticate.ts b/studio/lib/api/apiAuthenticate.tsindex 54a3c5b52a2..b3f195d2983 100644--- a/studio/lib/api/apiAuthenticate.ts+++ b/studio/lib/api/apiAuthenticate.ts@@ -1,11 +1,7 @@import type { NextApiRequest, NextApiResponse } from 'next'-import { Claims } from '@auth0/nextjs-auth0'import { readOnly } from './supabaseClient'import { SupaResponse, User } from 'types'-import { auth0 } from './auth0'-import { flattenNamespaceOnUser } from './apiHelpers'-import { config } from 'process'-import { getAuth0Id, getAuthUser, getIdentity, GOTRUE_ENABLED } from 'lib/gotrue'+import { getAuth0Id, getAuthUser, getIdentity } from 'lib/gotrue'/*** Use this method on api routes to check if user is authenticated and having required permissions.@@ -32,10 +28,6 @@ export async function apiAuthenticate(const { slug: orgSlug, ref: projectRef } = req.querytry {- // Check that they are logged in- // If no error throw from getAccessToken. That's good, we can continue- if (!(GOTRUE_ENABLED)) await auth0.getAccessToken(req, res)-const user = await fetchUser(req, res)if (!user) {return { error: new Error('The user does not exist') } as unknown as SupaResponse<User>@@ -59,35 +51,24 @@ async function fetchUser(req: NextApiRequest, res: NextApiResponse): Promise<anylet user_id_auth0 = nulllet gotrue_id = nulllet email = null- if (GOTRUE_ENABLED) {- const token = req.headers.authorization- if (!token) {- return res.status(401).end('Unauthorized: missing access token')- }- let { user: gotrue_user, error: authError } = await getAuthUser(token)- if (authError) {- throw authError- }- if (gotrue_user !== null) {- gotrue_id = gotrue_user?.id- email = gotrue_user.email-- let { identity, error } = getIdentity(gotrue_user)- if (error) throw error- if (identity?.provider !== undefined) {- user_id_auth0 = getAuth0Id(identity?.provider, identity?.id)- }- }- } else {- const session = auth0.getSession(req, res)- if (!session) {- return null++ const token = req.headers.authorization+ if (!token) {+ return res.status(401).end('Unauthorized: missing access token')+ }+ let { user: gotrue_user, error: authError } = await getAuthUser(token)+ if (authError) {+ throw authError+ }+ if (gotrue_user !== null) {+ gotrue_id = gotrue_user?.id+ email = gotrue_user.email++ let { identity, error } = getIdentity(gotrue_user)+ if (error) throw error+ if (identity?.provider !== undefined) {+ user_id_auth0 = getAuth0Id(identity?.provider, identity?.id)}- const { user: auth0_user } = session- const flattened = flattenNamespaceOnUser('https://supabase.io', auth0_user)- user_id_supabase = flattened.user_id_supabase- user_id_auth0 = flattened.user_id_auth0- email = flattened.email}if (user_id_supabase) {@@ -103,14 +84,11 @@ async function fetchUser(req: NextApiRequest, res: NextApiResponse): Promise<any`)- const { data } = GOTRUE_ENABLED- ? await query.eq('gotrue_id', gotrue_id).single()- : await await query.eq('auth0_id', user_id_auth0).single()-+ const { data } = await query.eq('gotrue_id', gotrue_id).single()return data}-async function checkMemberPermission(req: NextApiRequest, user: Claims) {+async function checkMemberPermission(req: NextApiRequest, user: any) {const org = await getOrganization(req)if (!org) {throw new Error('User organization does not exist')diff --git a/studio/lib/api/auth0.ts b/studio/lib/api/auth0.tsdeleted file mode 100644index b9b3ba874c1..00000000000--- a/studio/lib/api/auth0.ts+++ /dev/null@@ -1,32 +0,0 @@-import { initAuth0 } from '@auth0/nextjs-auth0'-import { IS_PLATFORM } from '../constants'--let auth0: any--if (IS_PLATFORM) {- auth0 = initAuth0({- baseURL: process.env.NEXT_PUBLIC_API_DOMAIN,- issuerBaseURL: `https://${process.env.AUTH0_DOMAIN}`,- clientID: process.env.AUTH0_CLIENT_ID,- clientSecret: process.env.AUTH0_CLIENT_SECRET,- secret: process.env.SESSION_COOKIE_SECRET,- authorizationParams: {- scope: 'openid profile email offline_access',- audience: process.env.AUTH0_AUDIENCE,- },- routes: {- callback: `/platform/auth0-callback`,- postLogoutRedirect: '/',- },- session: {- rollingDuration: 60 * 60 * 24,- absoluteDuration: 60 * 60 * 24 * 7,- cookie: {- sameSite: 'lax',- domain: process.env.COOKIE_DOMAIN || 'localhost',- },- },- })-}--export { auth0 }diff --git a/studio/lib/common/fetch/base.ts b/studio/lib/common/fetch/base.tsindex e78b452e198..7206fdbab4c 100644--- a/studio/lib/common/fetch/base.ts+++ b/studio/lib/common/fetch/base.ts@@ -1,4 +1,3 @@-import { GOTRUE_ENABLED } from 'lib/gotrue'import { tryParseJson } from 'lib/helpers'import { isUndefined } from 'lodash'import { SupaResponse } from 'types/base'@@ -110,7 +109,7 @@ export function constructHeaders(requestId: string, optionHeaders?: { [prop: str}const hasAuthHeader = !isUndefined(optionHeaders) && 'Authorization' in optionHeaders- if (GOTRUE_ENABLED && !hasAuthHeader) {+ if (!hasAuthHeader) {const accessToken = getAccessToken()if (accessToken) headers.Authorization = `Bearer ${accessToken}`}diff --git a/studio/lib/gotrue.ts b/studio/lib/gotrue.tsindex a4766f3ebbb..cbdfdf1772b 100644--- a/studio/lib/gotrue.ts+++ b/studio/lib/gotrue.ts@@ -1,6 +1,5 @@import { GoTrueClient, User } from '@supabase/gotrue-js'-export const GOTRUE_ENABLED = (process.env.NEXT_PUBLIC_GOTRUE_ENABLED === 'true') || falseexport const GOTRUE_URL = process.env.NEXT_PUBLIC_GOTRUE_URL || 'http://localhost:8000/auth/v1'export const auth = new GoTrueClient({@@ -8,7 +7,7 @@ export const auth = new GoTrueClient({autoRefreshToken: true,})-export const getAuthUser = async (token: String): Promise<any> => {+export const getAuthUser = async (token: String): Promise<any> => {try {const { data: user, error } = await auth.api.getUser(token.replace('Bearer ', ''))if (error) throw error