Snippets.ts787 lines · main
| 1 | const snippets = { |
| 2 | endpoint: (endpoint: string) => ({ |
| 3 | title: 'API URL', |
| 4 | bash: { |
| 5 | language: 'bash', |
| 6 | code: `${endpoint}`, |
| 7 | }, |
| 8 | js: { |
| 9 | language: 'bash', |
| 10 | code: `${endpoint}`, |
| 11 | }, |
| 12 | }), |
| 13 | install: () => ({ |
| 14 | title: 'Install', |
| 15 | bash: null, |
| 16 | js: { |
| 17 | language: 'bash', |
| 18 | code: `npm install --save @supabase/supabase-js`, |
| 19 | }, |
| 20 | }), |
| 21 | init: (endpoint: string) => ({ |
| 22 | title: 'Initializing', |
| 23 | bash: { |
| 24 | language: 'bash', |
| 25 | code: `# No client library required for Bash.`, |
| 26 | }, |
| 27 | js: { |
| 28 | language: 'js', |
| 29 | code: ` |
| 30 | import { createClient } from '@supabase/supabase-js' |
| 31 | const brivenUrl = '${endpoint}' |
| 32 | const brivenKey = process.env.BRIVEN_KEY |
| 33 | const briven = createClient(brivenUrl, brivenKey)`, |
| 34 | }, |
| 35 | python: { |
| 36 | language: 'python', |
| 37 | code: ` |
| 38 | import os |
| 39 | from briven import create_client, Client |
| 40 | url: str = '${endpoint}' |
| 41 | key: str = os.environ.get("BRIVEN_KEY") |
| 42 | briven: Client = create_client(url, key) |
| 43 | `, |
| 44 | }, |
| 45 | dart: { |
| 46 | language: 'dart', |
| 47 | code: ` |
| 48 | const brivenUrl = '${endpoint}'; |
| 49 | const brivenKey = String.fromEnvironment('BRIVEN_KEY'); |
| 50 | Future<void> main() async { |
| 51 | await Briven.initialize(url: brivenUrl, anonKey: brivenKey); |
| 52 | runApp(MyApp()); |
| 53 | }`, |
| 54 | }, |
| 55 | }), |
| 56 | authKey: (title: string, varName: string, apikey: string) => ({ |
| 57 | title: `${title}`, |
| 58 | bash: { |
| 59 | language: 'bash', |
| 60 | code: `${apikey}`, |
| 61 | }, |
| 62 | js: { |
| 63 | language: 'js', |
| 64 | code: `const ${varName} = '${apikey}'`, |
| 65 | }, |
| 66 | }), |
| 67 | authKeyExample: ( |
| 68 | defaultApiKey: string, |
| 69 | endpoint: string, |
| 70 | { keyName, showBearer = true }: { keyName?: string; showBearer?: boolean } |
| 71 | ) => ({ |
| 72 | title: 'Example usage', |
| 73 | bash: { |
| 74 | language: 'bash', |
| 75 | code: ` |
| 76 | curl '${endpoint}/rest/v1/' \\ |
| 77 | -H "apikey: ${defaultApiKey}" ${ |
| 78 | showBearer |
| 79 | ? `\\ |
| 80 | -H "Authorization: Bearer ${defaultApiKey}"` |
| 81 | : '' |
| 82 | } |
| 83 | `, |
| 84 | }, |
| 85 | js: { |
| 86 | language: 'js', |
| 87 | code: ` |
| 88 | const BRIVEN_URL = "${endpoint}" |
| 89 | const briven = createClient(BRIVEN_URL, process.env.${keyName || 'BRIVEN_KEY'}); |
| 90 | `, |
| 91 | }, |
| 92 | }), |
| 93 | rpcSingle: ({ |
| 94 | rpcName, |
| 95 | rpcParams, |
| 96 | endpoint, |
| 97 | apiKey, |
| 98 | showBearer = true, |
| 99 | }: { |
| 100 | rpcName: string |
| 101 | rpcParams: any[] |
| 102 | endpoint: string |
| 103 | apiKey: string |
| 104 | showBearer: boolean |
| 105 | }) => { |
| 106 | let rpcList = rpcParams.map((x) => `"${x.name}": "value"`).join(', ') |
| 107 | let noParams = !rpcParams.length |
| 108 | let bashParams = noParams ? '' : `\n-d '{ ${rpcList} }' \\` |
| 109 | let jsParams = noParams |
| 110 | ? '' |
| 111 | : `, {${ |
| 112 | rpcParams.length |
| 113 | ? rpcParams |
| 114 | .map((x) => `\n ${x.name}`) |
| 115 | .join(`, `) |
| 116 | .concat('\n ') |
| 117 | : '' |
| 118 | }}` |
| 119 | return { |
| 120 | title: 'Invoke function ', |
| 121 | bash: { |
| 122 | language: 'bash', |
| 123 | code: ` |
| 124 | curl -X POST '${endpoint}/rest/v1/rpc/${rpcName}' \\${bashParams} |
| 125 | -H "Content-Type: application/json" \\ |
| 126 | -H "apikey: ${apiKey}" ${ |
| 127 | showBearer |
| 128 | ? `\\ |
| 129 | -H "Authorization: Bearer ${apiKey}"` |
| 130 | : '' |
| 131 | } |
| 132 | `, |
| 133 | }, |
| 134 | js: { |
| 135 | language: 'js', |
| 136 | code: ` |
| 137 | let { data, error } = await briven |
| 138 | .rpc('${rpcName}'${jsParams}) |
| 139 | if (error) console.error(error) |
| 140 | else console.log(data) |
| 141 | `, |
| 142 | }, |
| 143 | } |
| 144 | }, |
| 145 | subscribeAll: (listenerName: string, resourceId: string) => ({ |
| 146 | title: 'Subscribe to all events', |
| 147 | bash: { |
| 148 | language: 'bash', |
| 149 | code: `# Realtime streams are only supported by our client libraries`, |
| 150 | }, |
| 151 | js: { |
| 152 | language: 'js', |
| 153 | code: ` |
| 154 | const ${listenerName} = briven.channel('custom-all-channel') |
| 155 | .on( |
| 156 | 'postgres_changes', |
| 157 | { event: '*', schema: 'public', table: '${resourceId}' }, |
| 158 | (payload) => { |
| 159 | console.log('Change received!', payload) |
| 160 | } |
| 161 | ) |
| 162 | .subscribe()`, |
| 163 | }, |
| 164 | }), |
| 165 | subscribeInserts: (listenerName: string, resourceId: string) => ({ |
| 166 | title: 'Subscribe to inserts', |
| 167 | bash: { |
| 168 | language: 'bash', |
| 169 | code: `# Realtime streams are only supported by our client libraries`, |
| 170 | }, |
| 171 | js: { |
| 172 | language: 'js', |
| 173 | code: ` |
| 174 | const ${listenerName} = briven.channel('custom-insert-channel') |
| 175 | .on( |
| 176 | 'postgres_changes', |
| 177 | { event: 'INSERT', schema: 'public', table: '${resourceId}' }, |
| 178 | (payload) => { |
| 179 | console.log('Change received!', payload) |
| 180 | } |
| 181 | ) |
| 182 | .subscribe()`, |
| 183 | }, |
| 184 | }), |
| 185 | subscribeUpdates: (listenerName: string, resourceId: string) => ({ |
| 186 | title: 'Subscribe to updates', |
| 187 | bash: { |
| 188 | language: 'bash', |
| 189 | code: `# Realtime streams are only supported by our client libraries`, |
| 190 | }, |
| 191 | js: { |
| 192 | language: 'js', |
| 193 | code: ` |
| 194 | const ${listenerName} = briven.channel('custom-update-channel') |
| 195 | .on( |
| 196 | 'postgres_changes', |
| 197 | { event: 'UPDATE', schema: 'public', table: '${resourceId}' }, |
| 198 | (payload) => { |
| 199 | console.log('Change received!', payload) |
| 200 | } |
| 201 | ) |
| 202 | .subscribe()`, |
| 203 | }, |
| 204 | }), |
| 205 | subscribeDeletes: (listenerName: string, resourceId: string) => ({ |
| 206 | title: 'Subscribe to deletes', |
| 207 | bash: { |
| 208 | language: 'bash', |
| 209 | code: `# Realtime streams are only supported by our client libraries`, |
| 210 | }, |
| 211 | js: { |
| 212 | language: 'js', |
| 213 | code: ` |
| 214 | const ${listenerName} = briven.channel('custom-delete-channel') |
| 215 | .on( |
| 216 | 'postgres_changes', |
| 217 | { event: 'DELETE', schema: 'public', table: '${resourceId}' }, |
| 218 | (payload) => { |
| 219 | console.log('Change received!', payload) |
| 220 | } |
| 221 | ) |
| 222 | .subscribe()`, |
| 223 | }, |
| 224 | }), |
| 225 | subscribeEq: (listenerName: string, resourceId: string, columnName: string, value: string) => ({ |
| 226 | title: 'Subscribe to specific rows', |
| 227 | bash: { |
| 228 | language: 'bash', |
| 229 | code: `# Realtime streams are only supported by our client libraries`, |
| 230 | }, |
| 231 | js: { |
| 232 | language: 'js', |
| 233 | code: ` |
| 234 | const ${listenerName} = briven.channel('custom-filter-channel') |
| 235 | .on( |
| 236 | 'postgres_changes', |
| 237 | { event: '*', schema: 'public', table: '${resourceId}', filter: '${columnName}=eq.${value}' }, |
| 238 | (payload) => { |
| 239 | console.log('Change received!', payload) |
| 240 | } |
| 241 | ) |
| 242 | .subscribe()`, |
| 243 | }, |
| 244 | }), |
| 245 | readAll: (resourceId: string, endpoint: string, apiKey: string) => ({ |
| 246 | title: 'Read all rows', |
| 247 | bash: { |
| 248 | language: 'bash', |
| 249 | code: ` |
| 250 | curl '${endpoint}/rest/v1/${resourceId}?select=*' \\ |
| 251 | -H "apikey: ${apiKey}" \\ |
| 252 | -H "Authorization: Bearer ${apiKey}" |
| 253 | `, |
| 254 | }, |
| 255 | js: { |
| 256 | language: 'js', |
| 257 | code: ` |
| 258 | let { data: ${resourceId}, error } = await briven |
| 259 | .from('${resourceId}') |
| 260 | .select('*') |
| 261 | `, |
| 262 | }, |
| 263 | }), |
| 264 | readColumns: ({ |
| 265 | title = 'Read specific columns', |
| 266 | resourceId, |
| 267 | endpoint, |
| 268 | apiKey, |
| 269 | columnName = 'some_column,other_column', |
| 270 | }: { |
| 271 | title?: string |
| 272 | resourceId: string |
| 273 | endpoint: string |
| 274 | apiKey: string |
| 275 | columnName?: string |
| 276 | }) => ({ |
| 277 | title, |
| 278 | bash: { |
| 279 | language: 'bash', |
| 280 | code: ` |
| 281 | curl '${endpoint}/rest/v1/${resourceId}?select=${columnName}' \\ |
| 282 | -H "apikey: ${apiKey}" \\ |
| 283 | -H "Authorization: Bearer ${apiKey}" |
| 284 | `, |
| 285 | }, |
| 286 | js: { |
| 287 | language: 'js', |
| 288 | code: ` |
| 289 | let { data: ${resourceId}, error } = await briven |
| 290 | .from('${resourceId}') |
| 291 | .select('${columnName}') |
| 292 | `, |
| 293 | }, |
| 294 | }), |
| 295 | readForeignTables: (resourceId: string, endpoint: string, apiKey: string) => ({ |
| 296 | title: 'Read referenced tables', |
| 297 | bash: { |
| 298 | language: 'bash', |
| 299 | code: ` |
| 300 | curl '${endpoint}/rest/v1/${resourceId}?select=some_column,other_table(foreign_key)' \\ |
| 301 | -H "apikey: ${apiKey}" \\ |
| 302 | -H "Authorization: Bearer ${apiKey}" |
| 303 | `, |
| 304 | }, |
| 305 | js: { |
| 306 | language: 'js', |
| 307 | code: ` |
| 308 | let { data: ${resourceId}, error } = await briven |
| 309 | .from('${resourceId}') |
| 310 | .select(\` |
| 311 | some_column, |
| 312 | other_table ( |
| 313 | foreign_key |
| 314 | ) |
| 315 | \`) |
| 316 | `, |
| 317 | }, |
| 318 | }), |
| 319 | readRange: (resourceId: string, endpoint: string, apiKey: string) => ({ |
| 320 | title: 'With pagination', |
| 321 | bash: { |
| 322 | language: 'bash', |
| 323 | code: ` |
| 324 | curl '${endpoint}/rest/v1/${resourceId}?select=*' \\ |
| 325 | -H "apikey: ${apiKey}" \\ |
| 326 | -H "Authorization: Bearer ${apiKey}" \\ |
| 327 | -H "Range: 0-9" |
| 328 | `, |
| 329 | }, |
| 330 | js: { |
| 331 | language: 'js', |
| 332 | code: ` |
| 333 | let { data: ${resourceId}, error } = await briven |
| 334 | .from('${resourceId}') |
| 335 | .select('*') |
| 336 | .range(0, 9) |
| 337 | `, |
| 338 | }, |
| 339 | }), |
| 340 | readFilters: (resourceId: string, endpoint: string, apiKey: string) => ({ |
| 341 | title: 'With filtering', |
| 342 | bash: { |
| 343 | language: 'bash', |
| 344 | code: ` |
| 345 | curl --get '${endpoint}/rest/v1/${resourceId}' \\ |
| 346 | -H "apikey: ${apiKey}" \\ |
| 347 | -H "Authorization: Bearer ${apiKey}" \\ |
| 348 | -H "Range: 0-9" \\ |
| 349 | -d "select=*" \\ |
| 350 | \\ |
| 351 | \`# Filters\` \\ |
| 352 | -d "column=eq.Equal+to" \\ |
| 353 | -d "column=gt.Greater+than" \\ |
| 354 | -d "column=lt.Less+than" \\ |
| 355 | -d "column=gte.Greater+than+or+equal+to" \\ |
| 356 | -d "column=lte.Less+than+or+equal+to" \\ |
| 357 | -d "column=like.*CaseSensitive*" \\ |
| 358 | -d "column=ilike.*CaseInsensitive*" \\ |
| 359 | -d "column=is.null" \\ |
| 360 | -d "column=in.(Array,Values)" \\ |
| 361 | -d "column=neq.Not+equal+to" \\ |
| 362 | \\ |
| 363 | \`# Arrays\` \\ |
| 364 | -d "array_column=cs.{array,contains}" \\ |
| 365 | -d "array_column=cd.{contained,by}" \\ |
| 366 | \\ |
| 367 | \`# Logical operators\` \\ |
| 368 | -d "column=not.like.Negate+filter" \\ |
| 369 | -d "or=(some_column.eq.Some+value,other_column.eq.Other+value)" |
| 370 | `, |
| 371 | }, |
| 372 | js: { |
| 373 | language: 'js', |
| 374 | code: ` |
| 375 | let { data: ${resourceId}, error } = await briven |
| 376 | .from('${resourceId}') |
| 377 | .select("*") |
| 378 | |
| 379 | // Filters |
| 380 | .eq('column', 'Equal to') |
| 381 | .gt('column', 'Greater than') |
| 382 | .lt('column', 'Less than') |
| 383 | .gte('column', 'Greater than or equal to') |
| 384 | .lte('column', 'Less than or equal to') |
| 385 | .like('column', '%CaseSensitive%') |
| 386 | .ilike('column', '%CaseInsensitive%') |
| 387 | .is('column', null) |
| 388 | .in('column', ['Array', 'Values']) |
| 389 | .neq('column', 'Not equal to') |
| 390 | |
| 391 | // Arrays |
| 392 | .contains('array_column', ['array', 'contains']) |
| 393 | .containedBy('array_column', ['contained', 'by']) |
| 394 | |
| 395 | // Logical operators |
| 396 | .not('column', 'like', 'Negate filter') |
| 397 | .or('some_column.eq.Some value, other_column.eq.Other value') |
| 398 | `, |
| 399 | }, |
| 400 | }), |
| 401 | insertSingle: (resourceId: string, endpoint: string, apiKey: string) => ({ |
| 402 | title: 'Insert a row', |
| 403 | bash: { |
| 404 | language: 'bash', |
| 405 | code: ` |
| 406 | curl -X POST '${endpoint}/rest/v1/${resourceId}' \\ |
| 407 | -H "apikey: ${apiKey}" \\ |
| 408 | -H "Authorization: Bearer ${apiKey}" \\ |
| 409 | -H "Content-Type: application/json" \\ |
| 410 | -H "Prefer: return=minimal" \\ |
| 411 | -d '{ "some_column": "someValue", "other_column": "otherValue" }' |
| 412 | `, |
| 413 | }, |
| 414 | js: { |
| 415 | language: 'js', |
| 416 | code: ` |
| 417 | const { data, error } = await briven |
| 418 | .from('${resourceId}') |
| 419 | .insert([ |
| 420 | { some_column: 'someValue', other_column: 'otherValue' }, |
| 421 | ]) |
| 422 | .select() |
| 423 | `, |
| 424 | }, |
| 425 | }), |
| 426 | insertMany: (resourceId: string, endpoint: string, apiKey: string) => ({ |
| 427 | title: 'Insert many rows', |
| 428 | bash: { |
| 429 | language: 'bash', |
| 430 | code: ` |
| 431 | curl -X POST '${endpoint}/rest/v1/${resourceId}' \\ |
| 432 | -H "apikey: ${apiKey}" \\ |
| 433 | -H "Authorization: Bearer ${apiKey}" \\ |
| 434 | -H "Content-Type: application/json" \\ |
| 435 | -d '[{ "some_column": "someValue" }, { "other_column": "otherValue" }]' |
| 436 | `, |
| 437 | }, |
| 438 | js: { |
| 439 | language: 'js', |
| 440 | code: ` |
| 441 | const { data, error } = await briven |
| 442 | .from('${resourceId}') |
| 443 | .insert([ |
| 444 | { some_column: 'someValue' }, |
| 445 | { some_column: 'otherValue' }, |
| 446 | ]) |
| 447 | .select() |
| 448 | `, |
| 449 | }, |
| 450 | }), |
| 451 | upsert: (resourceId: string, endpoint: string, apiKey: string) => ({ |
| 452 | title: 'Upsert matching rows', |
| 453 | bash: { |
| 454 | language: 'bash', |
| 455 | code: ` |
| 456 | curl -X POST '${endpoint}/rest/v1/${resourceId}' \\ |
| 457 | -H "apikey: ${apiKey}" \\ |
| 458 | -H "Authorization: Bearer ${apiKey}" \\ |
| 459 | -H "Content-Type: application/json" \\ |
| 460 | -H "Prefer: resolution=merge-duplicates" \\ |
| 461 | -d '{ "some_column": "someValue", "other_column": "otherValue" }' |
| 462 | `, |
| 463 | }, |
| 464 | js: { |
| 465 | language: 'js', |
| 466 | code: ` |
| 467 | const { data, error } = await briven |
| 468 | .from('${resourceId}') |
| 469 | .upsert({ some_column: 'someValue' }) |
| 470 | .select() |
| 471 | `, |
| 472 | }, |
| 473 | }), |
| 474 | update: (resourceId: string, endpoint: string, apiKey: string) => ({ |
| 475 | title: 'Update matching rows', |
| 476 | bash: { |
| 477 | language: 'bash', |
| 478 | code: ` |
| 479 | curl -X PATCH '${endpoint}/rest/v1/${resourceId}?some_column=eq.someValue' \\ |
| 480 | -H "apikey: ${apiKey}" \\ |
| 481 | -H "Authorization: Bearer ${apiKey}" \\ |
| 482 | -H "Content-Type: application/json" \\ |
| 483 | -H "Prefer: return=minimal" \\ |
| 484 | -d '{ "other_column": "otherValue" }' |
| 485 | `, |
| 486 | }, |
| 487 | js: { |
| 488 | language: 'js', |
| 489 | code: ` |
| 490 | const { data, error } = await briven |
| 491 | .from('${resourceId}') |
| 492 | .update({ other_column: 'otherValue' }) |
| 493 | .eq('some_column', 'someValue') |
| 494 | .select() |
| 495 | `, |
| 496 | }, |
| 497 | }), |
| 498 | delete: (resourceId: string, endpoint: string, apiKey: string) => ({ |
| 499 | title: 'Delete matching rows', |
| 500 | bash: { |
| 501 | language: 'bash', |
| 502 | code: ` |
| 503 | curl -X DELETE '${endpoint}/rest/v1/${resourceId}?some_column=eq.someValue' \\ |
| 504 | -H "apikey: ${apiKey}" \\ |
| 505 | -H "Authorization: Bearer ${apiKey}" |
| 506 | `, |
| 507 | }, |
| 508 | js: { |
| 509 | language: 'js', |
| 510 | code: ` |
| 511 | const { error } = await briven |
| 512 | .from('${resourceId}') |
| 513 | .delete() |
| 514 | .eq('some_column', 'someValue') |
| 515 | `, |
| 516 | }, |
| 517 | }), |
| 518 | authSignup: (endpoint: string, apiKey: string, randomPassword: string) => ({ |
| 519 | title: 'User signup', |
| 520 | bash: { |
| 521 | language: 'bash', |
| 522 | code: ` |
| 523 | curl -X POST '${endpoint}/auth/v1/signup' \\ |
| 524 | -H "apikey: ${apiKey}" \\ |
| 525 | -H "Content-Type: application/json" \\ |
| 526 | -d '{ |
| 527 | "email": "someone@email.com", |
| 528 | "password": "${randomPassword}" |
| 529 | }' |
| 530 | `, |
| 531 | }, |
| 532 | js: { |
| 533 | language: 'js', |
| 534 | code: ` |
| 535 | let { data, error } = await briven.auth.signUp({ |
| 536 | email: 'someone@email.com', |
| 537 | password: '${randomPassword}' |
| 538 | }) |
| 539 | `, |
| 540 | }, |
| 541 | }), |
| 542 | authLogin: (endpoint: string, apiKey: string, randomPassword: string) => ({ |
| 543 | title: 'User login', |
| 544 | bash: { |
| 545 | language: 'bash', |
| 546 | code: ` |
| 547 | curl -X POST '${endpoint}/auth/v1/token?grant_type=password' \\ |
| 548 | -H "apikey: ${apiKey}" \\ |
| 549 | -H "Content-Type: application/json" \\ |
| 550 | -d '{ |
| 551 | "email": "someone@email.com", |
| 552 | "password": "${randomPassword}" |
| 553 | }' |
| 554 | `, |
| 555 | }, |
| 556 | js: { |
| 557 | language: 'js', |
| 558 | code: ` |
| 559 | let { data, error } = await briven.auth.signInWithPassword({ |
| 560 | email: 'someone@email.com', |
| 561 | password: '${randomPassword}' |
| 562 | }) |
| 563 | `, |
| 564 | }, |
| 565 | }), |
| 566 | authMagicLink: (endpoint: string, apiKey: string) => ({ |
| 567 | title: 'User login', |
| 568 | bash: { |
| 569 | language: 'bash', |
| 570 | code: ` |
| 571 | curl -X POST '${endpoint}/auth/v1/magiclink' \\ |
| 572 | -H "apikey: ${apiKey}" \\ |
| 573 | -H "Content-Type: application/json" \\ |
| 574 | -d '{ |
| 575 | "email": "someone@email.com" |
| 576 | }' |
| 577 | `, |
| 578 | }, |
| 579 | js: { |
| 580 | language: 'js', |
| 581 | code: ` |
| 582 | let { data, error } = await briven.auth.signInWithOtp({ |
| 583 | email: 'someone@email.com' |
| 584 | }) |
| 585 | `, |
| 586 | }, |
| 587 | }), |
| 588 | authPhoneSignUp: (endpoint: string, apiKey: string) => ({ |
| 589 | title: 'Phone Signup', |
| 590 | bash: { |
| 591 | language: 'bash', |
| 592 | code: ` |
| 593 | curl -X POST '${endpoint}/auth/v1/signup' \\ |
| 594 | -H "apikey: ${apiKey}" \\ |
| 595 | -H "Content-Type: application/json" \\ |
| 596 | -d '{ |
| 597 | "phone": "+13334445555", |
| 598 | "password": "some-password" |
| 599 | }' |
| 600 | `, |
| 601 | }, |
| 602 | js: { |
| 603 | language: 'js', |
| 604 | code: ` |
| 605 | let { data, error } = await briven.auth.signUp({ |
| 606 | phone: '+13334445555', |
| 607 | password: 'some-password' |
| 608 | }) |
| 609 | `, |
| 610 | }, |
| 611 | }), |
| 612 | authMobileOTPLogin: (endpoint: string, apiKey: string) => ({ |
| 613 | title: 'Phone Login', |
| 614 | bash: { |
| 615 | language: 'bash', |
| 616 | code: ` |
| 617 | curl -X POST '${endpoint}/auth/v1/otp' \\ |
| 618 | -H "apikey: ${apiKey}" \\ |
| 619 | -H "Content-Type: application/json" \\ |
| 620 | -d '{ |
| 621 | "phone": "+13334445555" |
| 622 | }' |
| 623 | `, |
| 624 | }, |
| 625 | js: { |
| 626 | language: 'js', |
| 627 | code: ` |
| 628 | let { data, error } = await briven.auth.signInWithOtp({ |
| 629 | phone: '+13334445555' |
| 630 | }) |
| 631 | `, |
| 632 | }, |
| 633 | }), |
| 634 | authMobileOTPVerify: (endpoint: string, apiKey: string) => ({ |
| 635 | title: 'Verify Pin', |
| 636 | bash: { |
| 637 | language: 'bash', |
| 638 | code: ` |
| 639 | curl -X POST '${endpoint}/auth/v1/verify' \\ |
| 640 | -H "apikey: ${apiKey}" \\ |
| 641 | -H "Content-Type: application/json" \\ |
| 642 | -d '{ |
| 643 | "type": "sms", |
| 644 | "phone": "+13334445555", |
| 645 | "token": "123456" |
| 646 | }' |
| 647 | `, |
| 648 | }, |
| 649 | js: { |
| 650 | language: 'js', |
| 651 | code: ` |
| 652 | let { data, error } = await briven.auth.verifyOtp({ |
| 653 | phone: '+13334445555', |
| 654 | token: '123456', |
| 655 | type: 'sms' |
| 656 | }) |
| 657 | `, |
| 658 | }, |
| 659 | }), |
| 660 | authInvite: (endpoint: string, apiKey: string) => ({ |
| 661 | title: 'Invite User', |
| 662 | bash: { |
| 663 | language: 'bash', |
| 664 | code: ` |
| 665 | curl -X POST '${endpoint}/auth/v1/invite' \\ |
| 666 | -H "apikey: ${apiKey}" \\ |
| 667 | -H "Authorization: Bearer SERVICE_ROLE_KEY" \\ |
| 668 | -H "Content-Type: application/json" \\ |
| 669 | -d '{ |
| 670 | "email": "someone@email.com" |
| 671 | }' |
| 672 | `, |
| 673 | }, |
| 674 | js: { |
| 675 | language: 'js', |
| 676 | code: ` |
| 677 | let { data, error } = await briven.auth.admin.inviteUserByEmail('someone@email.com') |
| 678 | `, |
| 679 | }, |
| 680 | }), |
| 681 | authThirdPartyLogin: (endpoint: string, apiKey: string) => ({ |
| 682 | title: 'Third Party Login', |
| 683 | bash: { |
| 684 | language: 'bash', |
| 685 | code: ` |
| 686 | curl -X GET '${endpoint}/auth/v1/authorize?provider=github' \\ |
| 687 | -H "apikey: ${apiKey}" \\ |
| 688 | -H "Authorization: Bearer USER_TOKEN" \\ |
| 689 | -H "Content-Type: application/json" |
| 690 | `, |
| 691 | }, |
| 692 | js: { |
| 693 | language: 'js', |
| 694 | code: ` |
| 695 | let { data, error } = await briven.auth.signInWithOAuth({ |
| 696 | provider: 'github' |
| 697 | }) |
| 698 | `, |
| 699 | }, |
| 700 | }), |
| 701 | authUser: (endpoint: string, apiKey: string) => ({ |
| 702 | title: 'Get User', |
| 703 | bash: { |
| 704 | language: 'bash', |
| 705 | code: ` |
| 706 | curl -X GET '${endpoint}/auth/v1/user' \\ |
| 707 | -H "apikey: ${apiKey}" \\ |
| 708 | -H "Authorization: Bearer USER_TOKEN" |
| 709 | `, |
| 710 | }, |
| 711 | js: { |
| 712 | language: 'js', |
| 713 | code: ` |
| 714 | const { data: { user } } = await briven.auth.getUser() |
| 715 | `, |
| 716 | }, |
| 717 | }), |
| 718 | authRecover: (endpoint: string, apiKey: string) => ({ |
| 719 | title: 'Password Recovery', |
| 720 | bash: { |
| 721 | language: 'bash', |
| 722 | code: ` |
| 723 | curl -X POST '${endpoint}/auth/v1/recover' \\ |
| 724 | -H "apikey: ${apiKey}" \\ |
| 725 | -H "Content-Type: application/json" \\ |
| 726 | -d '{ |
| 727 | "email": "someone@email.com" |
| 728 | }' |
| 729 | `, |
| 730 | }, |
| 731 | js: { |
| 732 | language: 'js', |
| 733 | code: ` |
| 734 | let { data, error } = await briven.auth.resetPasswordForEmail(email) |
| 735 | `, |
| 736 | }, |
| 737 | }), |
| 738 | authUpdate: (endpoint: string, apiKey: string) => ({ |
| 739 | title: 'Update User', |
| 740 | bash: { |
| 741 | language: 'bash', |
| 742 | code: ` |
| 743 | curl -X PUT '${endpoint}/auth/v1/user' \\ |
| 744 | -H "apikey: ${apiKey}" \\ |
| 745 | -H "Authorization: Bearer USER_TOKEN" \\ |
| 746 | -H "Content-Type: application/json" \\ |
| 747 | -d '{ |
| 748 | "email": "someone@email.com", |
| 749 | "password": "new-password", |
| 750 | "data": { |
| 751 | "key": "value" |
| 752 | } |
| 753 | }' |
| 754 | `, |
| 755 | }, |
| 756 | js: { |
| 757 | language: 'js', |
| 758 | code: ` |
| 759 | const { data, error } = await briven.auth.updateUser({ |
| 760 | email: "new@email.com", |
| 761 | password: "new-password", |
| 762 | data: { hello: 'world' } |
| 763 | }) |
| 764 | `, |
| 765 | }, |
| 766 | }), |
| 767 | authLogout: (endpoint: string, apiKey: string) => ({ |
| 768 | title: 'User logout', |
| 769 | bash: { |
| 770 | language: 'bash', |
| 771 | code: ` |
| 772 | curl -X POST '${endpoint}/auth/v1/logout' \\ |
| 773 | -H "apikey: ${apiKey}" \\ |
| 774 | -H "Content-Type: application/json" \\ |
| 775 | -H "Authorization: Bearer USER_TOKEN" |
| 776 | `, |
| 777 | }, |
| 778 | js: { |
| 779 | language: 'js', |
| 780 | code: ` |
| 781 | let { error } = await briven.auth.signOut() |
| 782 | `, |
| 783 | }, |
| 784 | }), |
| 785 | } |
| 786 | |
| 787 | export default snippets |