File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -6,6 +6,8 @@ export function useEdgeDbEnv() {
66 NUXT_EDGEDB_USER : user ,
77 NUXT_EDGEDB_PASS : pass ,
88 NUXT_EDGEDB_DATABASE : database ,
9+ NUXT_EDGEDB_TLS_CA : tlsCA ,
10+ NUXT_EDGEDB_TLS_SECURITY : tlsSecurity ,
911 NUXT_EDGEDB_AUTH_BASE_URL : authBaseUrl = 'http://localhost:10702/db/edgedb/ext/auth/' ,
1012 NUXT_EDGEDB_OAUTH_CALLBACK : oAuthCallbackUrl = 'http://localhost:10702/db/edgedb/ext/auth/callback' ,
1113 NUXT_EDGEDB_AUTH_VERIFY_REDIRECT_URL : verifyRedirectUrl = 'http://localhost:3000/auth/verify' ,
@@ -36,5 +38,7 @@ export function useEdgeDbEnv() {
3638 pass,
3739 host,
3840 port,
41+ tlsCA,
42+ tlsSecurity : tlsSecurity as 'insecure' | 'no_host_verification' | 'strict' | 'default' ,
3943 }
4044}
Original file line number Diff line number Diff line change 1+ import type { EventHandlerRequest , H3Event } from 'h3'
2+ import { getCookie , sendRedirect , setCookie } from 'h3'
3+ import { useEdgeDb } from './useEdgeDb'
4+
5+ interface UseEdgeDbIdentityData < T = any > {
6+ identity : T
7+ cookie : string
8+ update : ( event ?: H3Event ) => Promise < void >
9+ logout : ( redirectTo ?: string ) => Promise < void >
10+ isLoggedIn : boolean
11+ }
12+
13+ export async function useEdgeDbIdentity < T > (
14+ req : H3Event < EventHandlerRequest > | undefined = undefined ,
15+ ) : Promise < UseEdgeDbIdentityData < T > > {
16+ const client = useEdgeDb ( req )
17+
18+ let token : string | undefined
19+
20+ let user : T | undefined
21+
22+ const update = async ( ) => {
23+ if ( req )
24+ token = getCookie ( req , 'edgedb-auth-token' )
25+
26+ user = client . querySingle ( `select global current_user;` ) as T
27+ }
28+
29+ const logout = async ( redirectTo : string | undefined ) => {
30+ if ( ! req )
31+ return
32+
33+ setCookie ( req , 'edgedb-auth-token' , '' )
34+
35+ if ( redirectTo )
36+ return sendRedirect ( req , '/' )
37+ }
38+
39+ await update ( )
40+
41+ const identityData = {
42+ isLoggedIn : ! ! user ,
43+ identity : user ,
44+ cookie : token ,
45+ update,
46+ logout,
47+ } as UseEdgeDbIdentityData
48+
49+ return identityData
50+ }
Original file line number Diff line number Diff line change @@ -3,9 +3,13 @@ import { defineNitroPlugin } from 'nitropack/dist/runtime/plugin'
33import { useEdgeDbEnv } from '../'
44
55export default defineNitroPlugin ( ( ) => {
6- const { dsn } = useEdgeDbEnv ( )
6+ const { dsn, tlsSecurity , tlsCA } = useEdgeDbEnv ( )
77
8- const client = createClient ( { dsn } )
8+ const client = createClient ( {
9+ dsn,
10+ tlsSecurity,
11+ tlsCA,
12+ } )
913
1014 // @ts -expect-error - untyped global
1115 globalThis . __nuxt_edgedb_client__ = client
You can’t perform that action at this time.
0 commit comments