Skip to content

Commit 05e5eb0

Browse files
committed
fix: use authRedirect
1 parent 20a91e6 commit 05e5eb0

2 files changed

Lines changed: 12 additions & 16 deletions

File tree

app/components/Header/AuthModal.client.vue

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,11 @@ const route = useRoute()
77
const { user, logout } = useAtproto()
88
99
async function handleBlueskySignIn() {
10-
await navigateTo(
11-
{
12-
path: '/api/auth/atproto',
13-
query: { handle: 'https://bsky.social', returnTo: route.fullPath },
14-
},
15-
{ external: true },
16-
)
10+
await authRedirect('https://bsky.social', { redirectTo: route.fullPath })
1711
}
1812
1913
async function handleCreateAccount() {
20-
await navigateTo(
21-
{
22-
path: '/api/auth/atproto',
23-
query: { handle: 'https://npmx.social', create: 'true', returnTo: route.fullPath },
24-
},
25-
{ external: true },
26-
)
14+
await authRedirect('https://npmx.social', { create: true, redirectTo: route.fullPath })
2715
}
2816
2917
async function handleLogin() {

app/utils/atproto/helpers.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
11
import type { FetchError } from 'ofetch'
22
import type { LocationQueryRaw } from 'vue-router'
33

4+
interface AuthRedirectOptions {
5+
create?: boolean
6+
redirectTo?: string
7+
}
8+
49
/**
510
* Redirect user to ATProto authentication
611
*/
7-
export async function authRedirect(identifier: string, create: boolean = false) {
12+
export async function authRedirect(identifier: string, options: AuthRedirectOptions = {}) {
813
let query: LocationQueryRaw = { handle: identifier }
9-
if (create) {
14+
if (options.create) {
1015
query = { ...query, create: 'true' }
1116
}
17+
if (options.redirectTo) {
18+
query = { ...query, returnTo: options.redirectTo }
19+
}
1220
await navigateTo(
1321
{
1422
path: '/api/auth/atproto',

0 commit comments

Comments
 (0)