The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
feat: auth verified filter (#8924)
hallidayo281f30bc6fd7
diff --git a/studio/components/interfaces/Auth/Users/Users.tsx b/studio/components/interfaces/Auth/Users/Users.tsxindex 768d85f0ff3..406d3c76955 100644--- a/studio/components/interfaces/Auth/Users/Users.tsx+++ b/studio/components/interfaces/Auth/Users/Users.tsx@@ -1,7 +1,7 @@import semver from 'semver'import { useEffect, useContext } from 'react'import { observer } from 'mobx-react-lite'-import { Button, Input, IconSearch, IconX, IconRefreshCw } from '@supabase/ui'+import { Button, Input, IconSearch, IconX, IconRefreshCw, Listbox, IconUsers } from '@supabase/ui'import { IS_PLATFORM } from 'lib/constants'import { PageContext } from 'pages/project/[ref]/auth/users'@@ -26,6 +26,11 @@ const Users = () => {PageState.filterInputValue = e.target.value}+ function onVerifiedFilterChange(e: any) {+ PageState.filterVerified = e+ onSearchUser()+ }+function onFilterKeyPress(e: any) {// enter keyif (e.keyCode == 13) onSearchUser()@@ -33,6 +38,7 @@ const Users = () => {function onSearchUser() {PageState.filterKeywords = PageState.filterInputValue+ PageState.filterVerified = PageState.filterVerifiedPageState.fetchData(1)}@@ -49,7 +55,7 @@ const Users = () => {return (<div className=""><div className="flex justify-between px-6 pt-6 pb-2">- <div className="relative flex space-x-1">+ <div className="relative flex space-x-4"><Inputsize="small"value={PageState.filterInputValue}@@ -70,6 +76,23 @@ const Users = () => {),]}/>+ <Listbox+ size="small"+ value={PageState.filterVerified}+ onChange={onVerifiedFilterChange}+ name="verified"+ id="verified"+ >+ <Listbox.Option label="All Users" value="">+ All Users+ </Listbox.Option>+ <Listbox.Option label="Verified Users" value="verified">+ Verified Users+ </Listbox.Option>+ <Listbox.Option label="Un-Verified Users" value="unverified">+ Un-Verified Users+ </Listbox.Option>+ </Listbox></div><div className="flex items-center"><Buttondiff --git a/studio/pages/api/auth/[ref]/users.ts b/studio/pages/api/auth/[ref]/users.tsindex 5839d8bb135..c68e00cc7f7 100644--- a/studio/pages/api/auth/[ref]/users.ts+++ b/studio/pages/api/auth/[ref]/users.ts@@ -25,15 +25,16 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {const handleGetAll = async (req: NextApiRequest, res: NextApiResponse) => {const headers = constructHeaders(req.headers)- const { keywords, limit, offset } = req.query+ const { keywords, limit, offset, verified } = req.queryconst limitInt = tryParseInt(limit as string) || 10const offsetInt = tryParseInt(offset as string) || 0const hasValidKeywords = keywords && keywords != ''+ const hasVerifiedValue = verified && verified != ''let queryCount = ''let queryUsers = ''- if (hasValidKeywords) {+ if (hasValidKeywords && !hasVerifiedValue) {queryCount = SqlString.format('SELECT count(*) from auth.users WHERE email ilike ?;', [`%${keywords}%`,])@@ -41,7 +42,53 @@ const handleGetAll = async (req: NextApiRequest, res: NextApiResponse) => {'SELECT * from auth.users WHERE email ilike ? ORDER BY created_at DESC LIMIT ? OFFSET ?;',[`%${keywords}%`, limitInt, offsetInt])- } else {+ }++ if (!hasValidKeywords && hasVerifiedValue) {+ if (verified === 'verified') {+ queryCount = SqlString.format(+ 'SELECT count(*) from auth.users WHERE (email_confirmed_at IS NOT NULL or phone_confirmed_at IS NOT NULL);'+ )+ queryUsers = SqlString.format(+ 'SELECT * from auth.users WHERE (email_confirmed_at IS NOT NULL or phone_confirmed_at IS NOT NULL) ORDER BY created_at DESC LIMIT ? OFFSET ?;',+ [limitInt, offsetInt]+ )+ }+ if (verified === 'unverified') {+ queryCount = SqlString.format(+ 'SELECT count(*) from auth.users WHERE (email_confirmed_at IS NULL AND phone_confirmed_at IS NULL);'+ )+ queryUsers = SqlString.format(+ 'SELECT * from auth.users WHERE (email_confirmed_at IS NULL AND phone_confirmed_at IS NULL) ORDER BY created_at DESC LIMIT ? OFFSET ?;',+ [limitInt, offsetInt]+ )+ }+ }++ if (hasValidKeywords && hasVerifiedValue) {+ if (verified === 'verified') {+ queryCount = SqlString.format(+ 'SELECT count(*) from auth.users WHERE (email_confirmed_at IS NOT NULL or phone_confirmed_at IS NOT NULL) AND email ilike ?;',+ [`%${keywords}%`]+ )+ queryUsers = SqlString.format(+ 'SELECT * from auth.users WHERE (email_confirmed_at IS NOT NULL or phone_confirmed_at IS NOT NULL) AND email ilike ? ORDER BY created_at DESC LIMIT ? OFFSET ?;',+ [`%${keywords}%`, limitInt, offsetInt]+ )+ }+ if (verified === 'unverified') {+ queryCount = SqlString.format(+ 'SELECT count(*) from auth.users WHERE (email_confirmed_at IS NULL AND phone_confirmed_at IS NULL) AND email ilike ?;',+ [`%${keywords}%`]+ )+ queryUsers = SqlString.format(+ 'SELECT * from auth.users WHERE (email_confirmed_at IS NULL AND phone_confirmed_at IS NULL) AND email ilike ? ORDER BY created_at DESC LIMIT ? OFFSET ?;',+ [`%${keywords}%`, limitInt, offsetInt]+ )+ }+ }++ if (!hasValidKeywords && !hasVerifiedValue) {queryCount = 'SELECT count(*) from auth.users;'queryUsers = SqlString.format('SELECT * from auth.users ORDER BY created_at DESC LIMIT ? OFFSET ?;',diff --git a/studio/pages/project/[ref]/auth/users.tsx b/studio/pages/project/[ref]/auth/users.tsxindex e0f5943b33c..25b4cd71939 100644--- a/studio/pages/project/[ref]/auth/users.tsx+++ b/studio/pages/project/[ref]/auth/users.tsx@@ -19,17 +19,20 @@ const PageLayout = ({ children }: PropsWithChildren<{}>) => {projectKpsVersion: undefined,filterInputValue: '',filterKeywords: '',+ filterVerified: undefined,users: [],totalUsers: 0,usersLoading: true,page: 1,pageLimit: 10,get fetchQuery() {- return {+ let queryObj = {limit: this.pageLimit,offset: (this.page - 1) * this.pageLimit,keywords: this.filterKeywords,}++ return this.filterVerified ? { ...queryObj, verified: this.filterVerified } : queryObj},get fromRow() {const value = this.pageLimit * (this.page - 1) + 1