···1-# sv
00000000000000000023-Everything you need to build a Svelte project, powered by [`sv`](https://github.com/sveltejs/cli).
45-## Creating a project
0067-If you're seeing this, you've probably already done this step. Congrats!
0089-```bash
10-# create a new project in the current directory
11-npx sv create
01213-# create a new project in my-app
14-npx sv create my-app
15```
1617-## Developing
1819-Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:
2021-```bash
22-npm run dev
2324-# or start the server and open the app in a new browser tab
25-npm run dev -- --open
00000026```
2728-## Building
000002930-To create a production version of your app:
3132-```bash
33-npm run build
34```
3536-You can preview the production build with `npm run preview`.
000003738-> To deploy your app, you may need to install an [adapter](https://svelte.dev/docs/kit/adapters) for your target environment.
000000000000
···1+# svelte atproto client oauth demo
2+3+this is a scaffold for how to get client side oauth working with sveltekit and atproto
4+using the `@atcute/oauth-browser-client` library.
5+6+perfect for static builds e.g. using github pages.
7+8+## how to install
9+10+### either clone this repo
11+12+1. clone this repo
13+2. run `npm install`
14+3. run `npm run dev`
15+4. go to `http://127.0.0.1:5179`
16+5. for deployment change the `SITE_URL` variable in `src/lib/oauth/const.ts`
17+(e.g. for github pages: `https://your-username.github.io`) and set your base in `svelte.config.js`
18+(e.g. for github pages: `base: '/your-repo-name/'`)
19+2021+### or manually install in your own project
2223+- copy the `src/lib/oauth` folder into your own project
24+- also copy the `src/routes/client-metadata.json` folder into your project
25+- add the following to your `src/routes/+layout.svelte`
2627+```svelte
28+<script>
29+ import { initClient } from '$lib/oauth';
3031+ onMount(() => {
32+ initClient();
33+ });
34+</script>
3536+{@render children()}
037```
3839+## how to use
4041+### login flow
4243+Either use the `LoginModal` component to render a login modal or use the `client` object to handle the login flow yourself.
04445+```ts
46+// handlin login flow yourself
47+import { client } from '$lib/oauth';
48+49+// methods:
50+client.login(handle); // login the user
51+client.isLoggedIn; // check if the user is logged in
52+client.logout(); // logout the user
53```
5455+LoginModal is a component that renders a login modal, add it for a quick login flow.
56+57+```svelte
58+<script>
59+ import { LoginModal, loginModalState } from '$lib/oauth';
60+</script>
6162+<LoginModal />
6364+<button onclick={() => loginModalState.show()}>Show Login Modal</button>
065```
6667+### make requests
68+69+Get the user's profile and make requests with the `client.rpc` object.
70+71+```ts
72+import { client } from '$lib/oauth';
7374+// get the user's profile
75+const profile = client.profile;
76+77+// make requests with the client.rpc object
78+const response = await client.rpc.request({
79+ type: 'get',
80+ nsid: 'app.bsky.feed.getActorLikes',
81+ params: {
82+ actor: client.profile?.did,
83+ limit: 10
84+ }
85+});
86+```
···1-import { metadata } from '$lib/client-metadata';
2import { json } from '@sveltejs/kit';
34export const prerender = true;
···1+import { metadata } from '$lib/oauth';
2import { json } from '@sveltejs/kit';
34export const prerender = true;
-3
svelte.config.js
···8 preprocess: vitePreprocess(),
910 kit: {
11- // adapter-auto only supports some environments, see https://svelte.dev/docs/kit/adapter-auto for a list.
12- // If your environment is not supported, or you settled on a specific environment, switch out the adapter.
13- // See https://svelte.dev/docs/kit/adapters for more information about adapters.
14 adapter: adapter(),
15 paths: {
16 base: process.env.NODE_ENV === 'development' ? '' : '/svelte-atproto-client-oauth'