···11-# sv
11+# svelte atproto client oauth demo
22+33+this is a scaffold for how to get client side oauth working with sveltekit and atproto
44+using the `@atcute/oauth-browser-client` library.
55+66+perfect for static builds e.g. using github pages.
77+88+## how to install
99+1010+### either clone this repo
1111+1212+1. clone this repo
1313+2. run `npm install`
1414+3. run `npm run dev`
1515+4. go to `http://127.0.0.1:5179`
1616+5. for deployment change the `SITE_URL` variable in `src/lib/oauth/const.ts`
1717+(e.g. for github pages: `https://your-username.github.io`) and set your base in `svelte.config.js`
1818+(e.g. for github pages: `base: '/your-repo-name/'`)
1919+22033-Everything you need to build a Svelte project, powered by [`sv`](https://github.com/sveltejs/cli).
2121+### or manually install in your own project
42255-## Creating a project
2323+- copy the `src/lib/oauth` folder into your own project
2424+- also copy the `src/routes/client-metadata.json` folder into your project
2525+- add the following to your `src/routes/+layout.svelte`
62677-If you're seeing this, you've probably already done this step. Congrats!
2727+```svelte
2828+<script>
2929+ import { initClient } from '$lib/oauth';
83099-```bash
1010-# create a new project in the current directory
1111-npx sv create
3131+ onMount(() => {
3232+ initClient();
3333+ });
3434+</script>
12351313-# create a new project in my-app
1414-npx sv create my-app
3636+{@render children()}
1537```
16381717-## Developing
3939+## how to use
18401919-Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:
4141+### login flow
20422121-```bash
2222-npm run dev
4343+Either use the `LoginModal` component to render a login modal or use the `client` object to handle the login flow yourself.
23442424-# or start the server and open the app in a new browser tab
2525-npm run dev -- --open
4545+```ts
4646+// handlin login flow yourself
4747+import { client } from '$lib/oauth';
4848+4949+// methods:
5050+client.login(handle); // login the user
5151+client.isLoggedIn; // check if the user is logged in
5252+client.logout(); // logout the user
2653```
27542828-## Building
5555+LoginModal is a component that renders a login modal, add it for a quick login flow.
5656+5757+```svelte
5858+<script>
5959+ import { LoginModal, loginModalState } from '$lib/oauth';
6060+</script>
29613030-To create a production version of your app:
6262+<LoginModal />
31633232-```bash
3333-npm run build
6464+<button onclick={() => loginModalState.show()}>Show Login Modal</button>
3465```
35663636-You can preview the production build with `npm run preview`.
6767+### make requests
6868+6969+Get the user's profile and make requests with the `client.rpc` object.
7070+7171+```ts
7272+import { client } from '$lib/oauth';
37733838-> To deploy your app, you may need to install an [adapter](https://svelte.dev/docs/kit/adapters) for your target environment.
7474+// get the user's profile
7575+const profile = client.profile;
7676+7777+// make requests with the client.rpc object
7878+const response = await client.rpc.request({
7979+ type: 'get',
8080+ nsid: 'app.bsky.feed.getActorLikes',
8181+ params: {
8282+ actor: client.profile?.did,
8383+ limit: 10
8484+ }
8585+});
8686+```
···11-import { metadata } from '$lib/client-metadata';
11+import { metadata } from '$lib/oauth';
22import { json } from '@sveltejs/kit';
3344export const prerender = true;
-3
svelte.config.js
···88 preprocess: vitePreprocess(),
991010 kit: {
1111- // adapter-auto only supports some environments, see https://svelte.dev/docs/kit/adapter-auto for a list.
1212- // If your environment is not supported, or you settled on a specific environment, switch out the adapter.
1313- // See https://svelte.dev/docs/kit/adapters for more information about adapters.
1411 adapter: adapter(),
1512 paths: {
1613 base: process.env.NODE_ENV === 'development' ? '' : '/svelte-atproto-client-oauth'