-
-
Notifications
You must be signed in to change notification settings - Fork 433
Expand file tree
/
Copy pathuseGitHub.ts
More file actions
37 lines (32 loc) · 760 Bytes
/
useGitHub.ts
File metadata and controls
37 lines (32 loc) · 760 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
function login(redirectTo?: string) {
const query: Record<string, string> = {}
if (redirectTo) {
query.returnTo = redirectTo
}
navigateTo(
{
path: '/api/auth/github',
query,
},
{ external: true },
)
}
export const useGitHub = createSharedComposable(function useGitHub() {
const {
data: user,
pending,
clear,
refresh,
} = useFetch<{ username: string } | null>('/api/auth/github/session', {
server: false,
immediate: !import.meta.test,
})
const isConnected = computed(() => !!user.value?.username)
async function logout() {
await $fetch('/api/auth/github/session', {
method: 'delete',
})
clear()
}
return { user, isConnected, pending, logout, login, refresh }
})