1- import  {  actor ,   UserError  }  from  "@rivetkit/core" ; 
1+ import  {  UserError ,   actor  }  from  "@rivetkit/core" ; 
22
33// Basic auth actor - requires API key 
44export  const  authActor  =  actor ( { 
@@ -9,11 +9,11 @@ export const authActor = actor({
99		if  ( ! apiKey )  { 
1010			throw  new  UserError ( "API key required" ,  {  code : "missing_auth"  } ) ; 
1111		} 
12- 		 
12+ 
1313		if  ( apiKey  !==  "valid-api-key" )  { 
1414			throw  new  UserError ( "Invalid API key" ,  {  code : "invalid_auth"  } ) ; 
1515		} 
16- 		 
16+ 
1717		return  {  userId : "user123" ,  token : apiKey  } ; 
1818	} , 
1919	actions : { 
@@ -30,17 +30,21 @@ export const intentAuthActor = actor({
3030	state : {  value : 0  } , 
3131	onAuth : ( opts )  =>  { 
3232		const  {  req,  intents,  params }  =  opts ; 
33- 		console . log ( ' intents' ,  intents ,  params ) ; 
33+ 		console . log ( " intents" ,  intents ,  params ) ; 
3434		const  role  =  ( params  as  any ) ?. role ; 
35- 		 
35+ 
3636		if  ( intents . has ( "create" )  &&  role  !==  "admin" )  { 
37- 			throw  new  UserError ( "Admin role required for create operations" ,  {  code : "insufficient_permissions"  } ) ; 
37+ 			throw  new  UserError ( "Admin role required for create operations" ,  { 
38+ 				code : "insufficient_permissions" , 
39+ 			} ) ; 
3840		} 
39- 		 
41+ 
4042		if  ( intents . has ( "action" )  &&  ! [ "admin" ,  "user" ] . includes ( role  ||  "" ) )  { 
41- 			throw  new  UserError ( "User or admin role required for actions" ,  {  code : "insufficient_permissions"  } ) ; 
43+ 			throw  new  UserError ( "User or admin role required for actions" ,  { 
44+ 				code : "insufficient_permissions" , 
45+ 			} ) ; 
4246		} 
43- 		 
47+ 
4448		return  {  role,  timestamp : Date . now ( )  } ; 
4549	} , 
4650	actions : { 
@@ -79,20 +83,18 @@ export const noAuthActor = actor({
7983export  const  asyncAuthActor  =  actor ( { 
8084	state : {  count : 0  } , 
8185	onAuth : async  ( opts )  =>  { 
82- 		const  {  req,  intents,  params }  =  opts ; 
83- 		// Simulate async auth check (e.g., database lookup) 
84- 		await  new  Promise ( resolve  =>  setTimeout ( resolve ,  10 ) ) ; 
85- 		
86+ 		const  {  params }  =  opts ; 
87+ 
8688		const  token  =  ( params  as  any ) ?. token ; 
8789		if  ( ! token )  { 
8890			throw  new  UserError ( "Token required" ,  {  code : "missing_token"  } ) ; 
8991		} 
90- 		 
92+ 
9193		// Simulate token validation 
9294		if  ( token  ===  "invalid" )  { 
9395			throw  new  UserError ( "Token is invalid" ,  {  code : "invalid_token"  } ) ; 
9496		} 
95- 		 
97+ 
9698		return  {  userId : `user-${ token }  ,  validated : true  } ; 
9799	} , 
98100	actions : { 
0 commit comments