File tree Expand file tree Collapse file tree 2 files changed +43
-21
lines changed Expand file tree Collapse file tree 2 files changed +43
-21
lines changed Original file line number Diff line number Diff line change @@ -45,6 +45,22 @@ export const authOptions: NextAuthOptions = {
4545 } ) ;
4646 }
4747
48+ // Check if the user has a team, if not create one
49+ if ( resp && ! resp . teamId ) {
50+ // Create a team for the admin
51+ const team = await prisma . team . create ( {
52+ data : {
53+ name : "Admin Team" ,
54+ } ,
55+ } ) ;
56+
57+ // Update the user with the teamId
58+ await prisma . user . update ( {
59+ where : { id : resp . id } ,
60+ data : { teamId : team . id } ,
61+ } ) ;
62+ }
63+
4864 if ( resp ) {
4965 // Any object returned will be saved in `user` property of the JWT
5066 const user = {
Original file line number Diff line number Diff line change @@ -4,28 +4,34 @@ import { loadEnvConfig } from "@next/env";
44loadEnvConfig ( process . cwd ( ) ) ;
55
66const chClient = createClient ( {
7- database : "default" ,
8- url : process . env . CLICK_HOUSE_HOST ,
9- username : process . env . CLICK_HOUSE_USER ,
10- password : process . env . CLICK_HOUSE_PASSWORD ,
11- compression : {
12- response : true ,
13- } ,
14- clickhouse_settings : {
15- async_insert : 1 ,
16- wait_for_async_insert : 1 ,
17- } ,
7+ database : "default" ,
8+ url : process . env . CLICK_HOUSE_HOST ,
9+ username : process . env . CLICK_HOUSE_USER ,
10+ password : process . env . CLICK_HOUSE_PASSWORD ,
11+ compression : {
12+ response : true ,
13+ } ,
14+ clickhouse_settings : {
15+ async_insert : 1 ,
16+ wait_for_async_insert : 1 ,
17+ connect_timeout : 30000 , // 30 seconds timeout
18+ } ,
19+ request_timeout : 30000 , // 30 seconds timeout
20+ keep_alive : {
21+ enabled : true ,
22+ idle_socket_ttl : 60000 ,
23+ } ,
1824} ) ;
1925
2026console . log ( "Creating Clickhouse DB if not exists..." ) ;
2127chClient
22- . query ( {
23- query : `CREATE DATABASE IF NOT EXISTS ${ process . env . CLICK_HOUSE_DATABASE_NAME } ` ,
24- } )
25- . then ( ( res ) => {
26- console . log ( res . query_id ) ;
27- } )
28- . catch ( ( err ) => {
29- console . error ( err ) ;
30- process . exit ( 1 ) ;
31- } ) ;
28+ . query ( {
29+ query : `CREATE DATABASE IF NOT EXISTS ${ process . env . CLICK_HOUSE_DATABASE_NAME } ` ,
30+ } )
31+ . then ( ( res ) => {
32+ console . log ( res . query_id ) ;
33+ } )
34+ . catch ( ( err ) => {
35+ console . error ( err ) ;
36+ process . exit ( 1 ) ;
37+ } ) ;
You can’t perform that action at this time.
0 commit comments