PageSourceSearch

https://ai-buddy-talk-now.lovable.app/assets/UserVerify-BxiHDBmj.js

js ai-buddy-talk-now.lovable.app collected 2026-10-03 03:19:22 UTC 13,258 bytes, 108 lines download raw bytes

1import{j as e}from"./ui-CcW7UyFZ.js";import{r as n}from"./vendor-mLzJK9mU.js";import{_ as R,a6 as d,U as V,W as H,H as p,I as j,ac as I,af as M,al as U,J as b,R as N,F as X,K as y,aw as D,ak as E,a4 as q,ax as B,a2 as F,a3 as G,N as u,ay as K,az as W,aA as z,aB as J,aC as Y,aD as Q,aE as Z}from"./index-CZj307i-.js";import{K as ee}from"./key-BHwMUgO1.js";import{R as S}from"./refresh-cw-Be4_GXDl.js";import"./auth-sqsEAYgo.js";import"./utils-Wy54MDZS.js";const le=()=>{const x=R(),[o,m]=n.useState(!0),[r,v]=n.useState(d()),[t,h]=n.useState(null),[k,w]=n.useState(""),[g,$]=n.useState(null),[f,C]=n.useState(!1),_=async(s=!1)=>{m(!0);const a=d();if(v(a),!a){console.log("[UserVerify] No session found, redirecting to login"),await l();return}if(a?.session_id){const i=await z("verify");if(console.log("[UserVerify] Server verification result:",i),h(i),!i.valid){console.log("[UserVerify] Session invalid, forcing logout:",i.reason),await l();return}}else if(a){const i=Date.now()<(a.expiresAt||0),O={valid:i,npub:a.npub,reason:i?"local_session":"expired_local"};if(h(O),!i){console.log("[UserVerify] Local session expired, forcing logout"),await l();return}}$(new Date),m(!1),s&&C(!0)},l=async()=>{console.log("[UserVerify] Forcing logout...");const s=d();if(s?.session_id)try{const a=J("/webhook/d787c38e-e102-4fb4-8e23-74124362e1b1");await fetch(a,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({tag:"logout",session_id:s.session_id,npub:s.npub,source:"user_verify_force_logout"})}),console.log("[UserVerify] Backend notified of logout")}catch(a){console.error("[UserVerify] Failed to notify backend:",a)}Y(),console.log("[UserVerify] Local session cleared"),x("/auth-admin")};n.useEffect(()=>{_(!0)},[]),n.useEffect(()=>{if(!f)return;const s=()=>{const i=Q();if(i<=0){console.log("[UserVerify] Session time expired"),l();return}w(Z(i))};s();const a=setInterval(s,6e4);return()=>clearInterval(a)},[r,f]);const L=async()=>{await l()},P=()=>{x("/nostr-client-setup")},A=()=>{_(!1)},T=s=>s?s.length<=12?s:`${s.slice(0,6)}...${s.slice(-6)}`:"N/A",c=s=>{if(!s)return"N/A";try{return new Date(s).toLocaleString("ro-RO")}catch{return s}};return e.jsx(V,{showSubBanner:!0,title:"Session Status",subtitle:"View and verify your current authentication session",children:e.jsx(H,{maxWidth:"2xl",children:e.jsxs("div",{className:"space-y-6 py-6",children:[e.jsxs(p,{className:"border-2",children:[e.jsx(j,{className:"pb-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:`p-2 rounded-full ${t?.valid?"bg-green-100 dark:bg-green-900/30":"bg-red-100 dark:bg-red-900/30"}`,children:o?e.jsx(I,{className:"h-6 w-6 animate-spin text-muted-foreground"}):t?.valid?e.jsx(M,{className:"h-6 w-6 text-green-600 dark:text-green-400"}):e.jsx(U,{className:"h-6 w-6 text-red-600 dark:text-red-400"})}),e.jsxs("div",{children:[e.jsx(b,{className:"text-xl",children:"Session Status"}),e.jsx(N,{children:o?"Verifying...":t?.valid?"Active Session":"No Active Session"})]})]}),e.jsx(X,{variant:t?.valid?"default":"destructive",className:"text-sm",children:t?.valid?"VALID":"INVALID"})]})}),e.jsxs(y,{className:"space-y-4",children:[r&&e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"flex items-start gap-3 p-3 rounded-lg bg-muted/50",children:[e.jsx(D,{className:"h-5 w-5 text-muted-foreground mt-0.5"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-medium text-muted-foreground",children:"Nostr Public Key"}),e.jsx("p",{className:"text-sm font-mono break-all",children:r.npub})]})]}),e.jsxs("div",{className:"flex items-start gap-3 p-3 rounded-lg bg-muted/50",children:[e.jsx(ee,{className:"h-5 w-5 text-muted-foreground mt-0.5"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-medium text-muted-foreground",children:"Session ID"}),e.jsx("p",{className:"text-sm font-mono",children:T(r.session_id)})]})]}),e.jsxs("div",{className:"flex items-start gap-3 p-3 rounded-lg bg-muted/50",children:[e.jsx(E,{className:"h-5 w-5 text-muted-foreground mt-0.5"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-muted-foreground",children:"Time Remaining"}),e.jsx("p",{className:"text-sm font-semibold",children:k})]})]}),e.jsxs("div",{className:"flex items-start gap-3 p-3 rounded-lg bg-muted/50",children:[e.jsx(q,{className:"h-5 w-5 text-muted-foreground mt-0.5"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-muted-foreground",children:"Remember Me"}),e.jsx("p",{className:"text-sm",children:r.rememberMe?"Yes (7 days)":"No (Browser session)"})]})]}),r.client_id&&e.jsxs("div",{className:"flex items-start gap-3 p-3 rounded-lg bg-muted/50",children:[e.jsx(B,{className:"h-5 w-5 text-muted-foreground mt-0.5"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-medium text-muted-foreground",children:"Client ID"}),e.jsx("p",{className:"text-sm font-mono break-all",children:r.client_id})]})]})]}),t&&!o&&e.jsxs("div",{className:"mt-4 pt-4 border-t",children:[e.jsxs("h4",{className:"text-sm font-medium mb-3 flex items-center gap-2",children:[e.jsx(S,{className:"h-4 w-4"}),"Server Verification Details"]}
1),e.jsxs("div",{className:"grid gap-2 text-sm",children:[t.created_at&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Created At:"}),e.jsx("span",{children:c(t.created_at)})]}),t.expires_at&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Expires At:"}),e.jsx("span",{children:c(t.expires_at)})]}),t.last_verified_at&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Last Verified:"}),e.jsx("span",{children:c(t.last_verified_at)})]}),t.reason&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Status Reason:"}),e.jsx("span",{className:"font-mono text-xs",children:t.reason})]}),g&&e.jsxs("div",{className:"flex justify-between text-muted-foreground text-xs mt-2",children:[e.jsx("span",{children:"Local check at:"}),e.jsx("span",{children:g.toLocaleTimeString("ro-RO")})]})]})]}),!r&&!o&&e.jsx(F,{children:e.jsx(G,{children:"No active session found. Please authenticate to continue."})})]})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-3",children:[e.jsxs(u,{onClick:A,variant:"outline",className:"flex-1",disabled:o,children:[e.jsx(S,{className:`h-4 w-4 mr-2 ${o?"animate-spin":""}`}),"Refresh Status"]}),r&&t?.valid&&e.jsxs(u,{onClick:P,className:"flex-1",children:["Continue to Setup",e.jsx(K,{className:"h-4 w-4 ml-2"})]}),e.jsxs(u,{onClick:L,variant:"destructive",className:"flex-1",children:[e.jsx(W,{className:"h-4 w-4 mr-2"}),"Logout"]})]}),e.jsxs(p,{className:"bg-muted/30",children:[e.jsxs(j,{className:"pb-2",children:[e.jsx(b,{className:"text-sm font-medium",children:"Generated Nginx Config (NPM Advanced Tab)"}),e.jsx(N,{className:"text-xs",children:"Paste in Proxy Host → Advanced tab"})]}),e.jsxs(y,{children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:"Configurație completă cu verificare webhook n8n, remember_me și token_ttl_seconds:"}),e.jsx("pre",{className:"text-xs bg-background p-3 rounded-lg overflow-x-auto whitespace-pre-wrap",children:`# ======================================
2# Nostr Auth – Nginx Proxy Manager Config
3# FINAL – Cookie session_id + npub + verificare periodică
4# ======================================
5# ⚠️ PASTE THIS IN: Nginx Proxy Manager → Proxy Host → Advanced tab
6# ⚠️ IMPORTANT: NPM requires ALL directives inside location blocks!
7# ======================================
8
9# -------- CONFIG --------
10set $auth_service "https://botrift.com";
11set $backend_app "http://172.18.0.1:32768";
12set $client_id "cli_XXXXXXXX";
13set $redirect_uri "https://test.example.com/__auth/callback";
14set $webhook_verify "https://n8n.example.com/webhook/XXXX-XXXX";
15
16# ─────────────────────────────────────
17# 1) CALLBACK - Generate cookies (exact match has priority)
18# ─────────────────────────────────────
19location = /__auth/callback {
20  if ($arg_session_id = "") {
21    return 302 $auth_service/user/loghin?client_id=$client_id&redirect_uri=$redirect_uri;
22  }
23  
24  if ($arg_npub = "") {
25    return 302 $auth_service/user/loghin?client_id=$client_id&redirect_uri=$redirect_uri;
26  }
27
28  set $cookie_session "session_id=$arg_session_id; Path=/; HttpOnly; Secure; SameSite=Lax";
29  set $cookie_npub "npub=$arg_npub; Path=/; HttpOnly; Secure; SameSite=Lax";
30
31  if ($arg_max_age != "") {
32    set $cookie_session "session_id=$arg_session_id; Path=/; Max-Age=$arg_max_age; HttpOnly; Secure; SameSite=Lax";
33    set $cookie_npub "npub=$arg_npub; Path=/; Max-Age=$arg_max_age; HttpOnly; Secure; SameSite=Lax";
34  }
35
36  add_header Set-Cookie $cookie_session always;
37  add_header Set-Cookie $cookie_npub always;
38  add_header Set-Cookie "nostr_auth_grace=1; Path=/; Max-Age=10; HttpOnly; Secure; SameSite=Lax" always;
39
40  set $redirect_target $arg_state;
41  if ($arg_state = "") {
42    set $redirect_target "/";
43  }
44  
45  return 302 $redirect_target;
46}
47
48# ─────────────────────────────────────
49# 2) VERIFY - Session verification (internal)
50# Sends: {"tag":"verify","session_id":"...","npub":"...","client_id":"..."}
51# Expects: HTTP 200 = valid, HTTP 401 = invalid
52# ─────────────────────────────────────
53location = /__auth/verify {
54  internal;
55
56  if ($cookie_session_id = "") {
57    return 401;
58  }
59
60  if ($cookie_nostr_auth_grace != "") {
61    return 200;
62  }
63
64  proxy_pass $webhook_verify;
65  proxy_method POST;
66  proxy_set_header Content-Type "application/json";
67  proxy_pass_request_body off;
68  proxy_set_header Content-Length "";
69  
70  set $verify_body '{"tag":"verify","session_id":"$cookie_session_id","npub":"$cookie_npub","client_id":"$client_id"}';
71  proxy_set_body $verify_body;
72}
73
74# ─────────────────────────────────────
75# 3) LOGOUT - Clear cookies
76# ─────────────────────────────────────
77location = /__auth/logout {
78  add_header Set-Cookie "session_id=; Path=/; Max-Age=0; HttpOnly; Secure; SameSite=Lax" always;
79  add_header Set-Cookie "npub=; Path=/; Max-Age=0; HttpOnly; Secure; SameSite=Lax" always;
80  add_header Set-Cookie "nostr_auth_grace=; Path=/; Max-Age=0; HttpOnly; Secure; SameSite=Lax" always;
81  
82  if ($request_method = POST) {
83    return 200 'OK';
84  }
85  
86  return 302 /;
87}
88
89# ─────────────────────────────────────
90# 4) REDIRECT TO LOGIN
91# ─────────────────────────────────────
92location @nostr_login {
93  add_header Set-Cookie "session_id=; Path=/; Max-Age=0; HttpOnly; Secure; SameSite=Lax" always;
94  add_header Set-Cookie "npub=; Path=/; Max-Age=0; HttpOnly; Secure; SameSite=Lax" always;
95  add_header Set-Cookie "nostr_auth_grace=; Path=/; Max-Age=0; HttpOnly; Secure; SameSite=Lax" always;
96  return 302 $auth_service/user/loghin?client_id=$client_id&redirect_uri=$redirect_uri&state=$scheme://$host$request_uri;
97}
98
99# ─────────────────────────────────────
100# 5) PROTECTED ROOT - auth_request MUST be inside location block!
101# NPM merges this with its proxy_pass to your backend
102# ─────────────────────────────────────
103location / {
104  auth_request /__auth/verify;
105  error_page 401 403 = @nostr_login;
106  
107  # NPM handles proxy_pass automatically
108}`}),e.jsxs("div",{className:"mt-3 space-y-2",children:[e.jsxs("div",{className:"p-2 bg-green-100 dark:bg-green-900/30 rounded text-xs",children:[e.jsx("strong",{children:"✅ Cookie Generation:"})," Cookie-ul ",e.jsx("code",{children:"session_id"})," se generează din parametrul URL. Cu ",e.jsx("code",{children:"remember_me=true"})," folosește ",e.jsx("code",{children:"Max-Age=token_ttl_seconds"}),", altfel cookie de sesiune."]}
108),e.jsxs("div",{className:"p-2 bg-blue-100 dark:bg-blue-900/30 rounded text-xs",children:[e.jsx("strong",{children:"🔄 Verificare Periodică:"})," La fiecare request, ",e.jsx("code",{children:"auth_request"})," trimite la n8n:",e.jsx("code",{children:'{"tag":"verify","session_id":"...","client_id":"..."}'})]}),e.jsxs("div",{className:"p-2 bg-amber-100 dark:bg-amber-900/30 rounded text-xs",children:[e.jsx("strong",{children:"⚠️ n8n Setup:"})," Webhook-ul trebuie să returneze HTTP 200 pentru ",e.jsx("code",{children:"auth:true"}),"și HTTP 401 pentru ",e.jsx("code",{children:"auth:false"})," (sesiune expirată)."]})]})]})]})]})})})};export{le as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.