Skip to content

Commit

Permalink
feat: RPC get_user_by_mobile RPC for Admin
Browse files Browse the repository at this point in the history
  • Loading branch information
fahimalizain committed Dec 22, 2023
1 parent 7ce2889 commit bc4fd3f
Show file tree
Hide file tree
Showing 7 changed files with 467 additions and 14 deletions.
21 changes: 11 additions & 10 deletions libs/supabase/prisma/seed.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import { PrismaClient } from '@prisma/client'
import { create_profile_on_signup } from './seeds/create_profile_on_signup'
import { PrismaClient } from '@prisma/client';
import { create_profile_on_signup } from './seeds/create_profile_on_signup';
import { create_get_user_by_mobile } from './seeds/get_user_by_mobile';

const prisma = new PrismaClient()
const prisma = new PrismaClient();

async function main() {
await create_profile_on_signup(prisma)
await create_profile_on_signup(prisma);
await create_get_user_by_mobile(prisma);
}


main()
.then(async () => {
await prisma.$disconnect()
await prisma.$disconnect();
})
.catch(async (e) => {
console.error(e)
await prisma.$disconnect()
process.exit(1)
})
console.error(e);
await prisma.$disconnect();
process.exit(1);
});
22 changes: 22 additions & 0 deletions libs/supabase/prisma/seeds/get_user_by_mobile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { PrismaClient } from '@prisma/client';

export async function create_get_user_by_mobile(prisma: PrismaClient) {
await prisma.$executeRaw`
CREATE OR REPLACE FUNCTION public.get_user_by_mobile(mobile text)
RETURNS SETOF auth.users AS
$$
BEGIN
RETURN QUERY
SELECT
-- id, email, email_confirmed_at, invited_at,
-- phone, phone_confirmed_at
-- raw_app_meta_data, raw_user_meta_data, is_super_admin,
-- created_at, updated_at, deleted_at
*
FROM auth.users WHERE phone = mobile;
END;
$$
LANGUAGE plpgsql
SECURITY INVOKER;
`;
}
5 changes: 3 additions & 2 deletions libs/supabase/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": [
"libs/supabase/**/*.ts",
"libs/supabase/src/**/*.ts",
"libs/supabase/prisma/**/*.ts",
"libs/supabase/package.json"
]
}
Expand Down Expand Up @@ -48,7 +49,7 @@
"cwd": "libs/supabase",
"commands": [
"npx supabase gen types typescript --linked --schema public> ./src/supabase_types.ts",
"npx nx lint supabase --fix"
"npx nx lint supabase --fix --force"
]
}
}
Expand Down
8 changes: 6 additions & 2 deletions libs/supabase/src/supabase_types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

export type Json =
| string
| number
Expand Down Expand Up @@ -323,7 +322,12 @@ export interface Database {
[_ in never]: never
}
Functions: {
[_ in never]: never
get_user_by_mobile: {
Args: {
mobile: string
}
Returns: unknown[]
}
}
Enums: {
[_ in never]: never
Expand Down
1 change: 1 addition & 0 deletions libs/supabase/supabase/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FAST2SMS_API_KEY=
5 changes: 5 additions & 0 deletions libs/supabase/supabase/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Updating Secrets

```
supabase secrets set --env-file ./supabase/.env
```
Loading

0 comments on commit bc4fd3f

Please sign in to comment.