Skip to content

Commit

Permalink
Merge pull request #50 from strideynet/kevslashnull/admin-commonjs-fix
Browse files Browse the repository at this point in the history
Fix atproto imports due to CommonJS
  • Loading branch information
strideynet authored Jul 24, 2023
2 parents fbb8551 + c2c382b commit 024cce8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
4 changes: 2 additions & 2 deletions web/admin/components/shared/bsky/description.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<script lang="ts" setup>
import { RichText } from "@atproto/api";
import * as atproto from "@atproto/api";
import { newAgent } from "~/lib/auth";
const props = defineProps<{ description: string }>();
const segments = ref();
const updateDescription = async () => {
const descriptionRichText = new RichText(
const descriptionRichText = new atproto.RichText(
{ text: props.description },
{ cleanNewlines: true }
);
Expand Down
17 changes: 9 additions & 8 deletions web/admin/lib/auth.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { AtpSessionData, BskyAgent } from "@atproto/api";
import * as atproto from "@atproto/api";

export const COOKIE_NAME = "furrylist-bsky-session";
const BSKY_API = "https://bsky.social";

export function newAgent(): BskyAgent {
const agent = new BskyAgent({ service: BSKY_API });
export function newAgent(): atproto.BskyAgent {
const agent = new atproto.BskyAgent({ service: BSKY_API });

const user = useState<AtpSessionData>("user").value;
const user = useState<atproto.AtpSessionData>("user").value;

if (user) {
agent.session = user;
Expand All @@ -28,7 +28,7 @@ export async function login(
): Promise<{ error: any; success: boolean }> {
const agent = newAgent();
let success: boolean;
let data: AtpSessionData;
let data: atproto.AtpSessionData;

try {
const result = await agent.login({ identifier, password });
Expand All @@ -42,14 +42,14 @@ export async function login(
return { success, error: "Invalid identifier or password" };
}

useCookie<AtpSessionData>(COOKIE_NAME).value = data;
useCookie<atproto.AtpSessionData>(COOKIE_NAME).value = data;
useState("user").value = data;

return { success, error: null };
}

export async function fetchUser(): Promise<AtpSessionData | null> {
const cookie = useCookie<AtpSessionData | null>(COOKIE_NAME, {
export async function fetchUser(): Promise<atproto.AtpSessionData | null> {
const cookie = useCookie<atproto.AtpSessionData | null>(COOKIE_NAME, {
expires: new Date(Date.now() + 1000 * 60 * 60 * 24 * 30),
});

Expand All @@ -70,6 +70,7 @@ export async function fetchUser(): Promise<AtpSessionData | null> {
case "expired":
cookie.value = null;
useState("user").value = null;
break;
default:
break;
}
Expand Down
6 changes: 3 additions & 3 deletions web/info/src/lib/atp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { writable } from 'svelte/store';

import { ATP_API, ATP_SESSION_COOKIE } from '$lib/constants';

import { BskyAgent } from '@atproto/api';
import * as atproto from '@atproto/api';

import type { AtpSessionData, AtpSessionEvent } from '@atproto/api';

const session = writable<AtpSessionData | null>(null),
agent = writable<BskyAgent | null>(null);
agent = writable<atproto.BskyAgent | null>(null);

const setupSession = () => {
let session: AtpSessionData | null = null;
Expand Down Expand Up @@ -70,7 +70,7 @@ const setupAgent = () => {
}
};

return new BskyAgent({ service: ATP_API, persistSession: persistSessionWith });
return new atproto.BskyAgent({ service: ATP_API, persistSession: persistSessionWith });
};

export { agent, session, setupAgent, setupSession };

2 comments on commit 024cce8

@vercel
Copy link

@vercel vercel bot commented on 024cce8 Jul 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 024cce8 Jul 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.