Auth.svelte 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <script lang="ts">
  2. import {
  3. state as _state,
  4. createAuth,
  5. deleteAuth,
  6. renameAuth,
  7. updateAuthParams,
  8. } from "$lib/state.svelte";
  9. import { Button } from "$lib/components/ui/button";
  10. import { Trash, Plus } from "@lucide/svelte";
  11. import { Input } from "./ui/input";
  12. import Editable from "./Editable.svelte";
  13. import AuthParams from "./AuthParams.svelte";
  14. </script>
  15. <div class="space-y-6">
  16. <!-- Inherit checkbox -->
  17. <!-- <div class="flex items-center gap-3"> -->
  18. <!-- <Checkbox checked={inherit} onCheckedChange={(v) => toggleInherit(!!v)} /> -->
  19. <!-- <span class="text-sm">Inherit auth from parent collection</span> -->
  20. <!-- </div> -->
  21. <div class="border">
  22. <h1 class="p-2">Workspace authentication</h1>
  23. <p class="p-2 text-sm">
  24. Create workspace-wide authentication schemes. Use the schemes created here
  25. in request/collection tabs.
  26. </p>
  27. </div>
  28. <!-- Create auth -->
  29. <div class="space-y-2">
  30. <div class="flex gap-2">
  31. <Button variant="outline" onclick={() => createAuth("Token")}>
  32. <Plus class="h-4 w-4 mr-2" /> Token
  33. </Button>
  34. <Button variant="outline" onclick={() => createAuth("Basic")}>
  35. <Plus class="h-4 w-4 mr-2" /> Basic
  36. </Button>
  37. <Button variant="outline" onclick={() => createAuth("OAuth")}>
  38. <Plus class="h-4 w-4 mr-2" /> OAuth
  39. </Button>
  40. </div>
  41. </div>
  42. {#each _state.auth as auth}
  43. <div class="border">
  44. <div class="flex items-center">
  45. <Editable
  46. bind:value={auth.name}
  47. onSave={(value) => {
  48. renameAuth(auth.id, value);
  49. }}
  50. >
  51. {#snippet display({ value, startEdit })}
  52. <h2 ondblclick={startEdit}>
  53. {auth.name}
  54. </h2>
  55. {/snippet}
  56. </Editable>
  57. <Trash
  58. class="ml-2 h-4 w-4 cursor-pointer text-muted-foreground hover:text-destructive"
  59. size={16}
  60. onclick={() => deleteAuth(auth.id)}
  61. />
  62. </div>
  63. <div class="p-2">
  64. <AuthParams {auth} readonly={false} />
  65. </div>
  66. </div>
  67. {/each}
  68. </div>