Skip to content

Commit 0f85fce

Browse files
feat: add auth + google auth provider for web (#6505)
* handle google auth * fix lint * fix auto login button type * update i18 language + userprofilemenu position * minor api rename for consistency
1 parent 973f77c commit 0f85fce

37 files changed

+1724
-229
lines changed

extensions-web/src/index.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@ export { default as ConversationalExtensionWeb } from './conversational-web'
99
export { default as JanProviderWeb } from './jan-provider-web'
1010
export { default as MCPExtensionWeb } from './mcp-web'
1111

12+
// Re-export auth functionality
13+
export {
14+
JanAuthService,
15+
getSharedAuthService,
16+
AUTH_STORAGE_KEYS,
17+
AUTH_EVENTS,
18+
AUTH_BROADCAST_CHANNEL,
19+
} from './shared/auth'
20+
1221
// Re-export types
1322
export type {
1423
WebExtensionRegistry,
@@ -17,12 +26,21 @@ export type {
1726
WebExtensionLoader,
1827
ConversationalWebModule,
1928
JanProviderWebModule,
20-
MCPWebModule
29+
MCPWebModule,
2130
} from './types'
2231

32+
// Re-export auth types
33+
export type {
34+
User,
35+
AuthTokens,
36+
AuthProvider,
37+
AuthProviderRegistry,
38+
ProviderType,
39+
} from './shared/auth'
40+
2341
// Extension registry for dynamic loading
2442
export const WEB_EXTENSIONS: WebExtensionRegistry = {
2543
'conversational-web': () => import('./conversational-web'),
2644
'jan-provider-web': () => import('./jan-provider-web'),
2745
'mcp-web': () => import('./mcp-web'),
28-
}
46+
}

extensions-web/src/shared/auth.ts

Lines changed: 0 additions & 219 deletions
This file was deleted.
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/**
2+
* Generic Authentication API Layer
3+
* Generic API calls for authentication (not provider-specific)
4+
*/
5+
6+
import { AuthTokens } from './types'
7+
import { AUTH_ENDPOINTS } from './const'
8+
9+
declare const JAN_API_BASE: string
10+
11+
/**
12+
* Logout user on server
13+
*/
14+
export async function logoutUser(): Promise<void> {
15+
const response = await fetch(`${JAN_API_BASE}${AUTH_ENDPOINTS.LOGOUT}`, {
16+
method: 'POST',
17+
credentials: 'include',
18+
headers: {
19+
'Content-Type': 'application/json',
20+
},
21+
})
22+
23+
if (!response.ok) {
24+
console.warn(`Logout failed with status: ${response.status}`)
25+
}
26+
}
27+
28+
/**
29+
* Guest login
30+
*/
31+
export async function guestLogin(): Promise<AuthTokens> {
32+
const response = await fetch(`${JAN_API_BASE}${AUTH_ENDPOINTS.GUEST_LOGIN}`, {
33+
method: 'POST',
34+
credentials: 'include',
35+
headers: {
36+
'Content-Type': 'application/json',
37+
},
38+
})
39+
40+
if (!response.ok) {
41+
throw new Error(
42+
`Guest login failed: ${response.status} ${response.statusText}`
43+
)
44+
}
45+
46+
return response.json() as Promise<AuthTokens>
47+
}
48+
49+
/**
50+
* Refresh token (works for both guest and authenticated users)
51+
*/
52+
export async function refreshToken(): Promise<AuthTokens> {
53+
const response = await fetch(
54+
`${JAN_API_BASE}${AUTH_ENDPOINTS.REFRESH_TOKEN}`,
55+
{
56+
method: 'GET',
57+
credentials: 'include',
58+
}
59+
)
60+
61+
if (!response.ok) {
62+
throw new Error(
63+
`Token refresh failed: ${response.status} ${response.statusText}`
64+
)
65+
}
66+
67+
return response.json() as Promise<AuthTokens>
68+
}

0 commit comments

Comments
 (0)