@@ -44,70 +44,55 @@ const functionDef = (state: EmulatorState, commandOptions: string[]) => {
4444 return { output : "" , type : "text" } ;
4545} ;
4646
47- export const handlePasswordPromptKeyPress = async (
47+ export const authenticateWithPasskey = async (
4848 emulator : Emulator ,
49- emulatorState : EmulatorState ,
50- _password : string ,
51- key : string ,
52- ctrlKey : boolean = false
53- ) : Promise < boolean > => {
49+ emulatorState : EmulatorState
50+ ) : Promise < void > => {
5451 const promptState = emulatorState . getPasswordPromptState ( ) ;
55- if ( ! promptState ) return false ;
52+ if ( ! promptState ) return ;
53+
54+ try {
55+ const { data : authOptions } = await axios . post (
56+ "https://api.maxrosoff.com/admin/passkey-auth-options"
57+ ) ;
58+
59+ const authResponse = await startAuthentication ( { optionsJSON : authOptions } ) ;
60+ const { data : authResult } = await axios . post ( "https://api.maxrosoff.com/admin/passkey-auth" , {
61+ response : authResponse ,
62+ challenge : authOptions . challenge
63+ } ) ;
64+
65+ const existingAdminMode = emulatorState . getAdminConsoleMode ( ) ;
66+ emulatorState . setAdminConsoleMode ( {
67+ ...existingAdminMode ,
68+ authToken : authResult . token
69+ } ) ;
70+
71+ const commandMapping = emulatorState . getCommandMapping ( ) ;
72+ const result = emulator . runCommand ( commandMapping , promptState . targetCommand , [
73+ emulatorState ,
74+ promptState . targetOptions
75+ ] ) ;
5676
57- if ( key === "c" && ctrlKey ) {
5877 emulatorState . setPasswordPromptState ( undefined ) ;
59- return true ;
60- }
6178
62- if ( key === "Enter" ) {
63- try {
64- const { data : authOptions } = await axios . post (
65- "https://api.maxrosoff.com/admin/passkey-auth-options"
66- ) ;
67-
68- const authResponse = await startAuthentication ( authOptions ) ;
69-
70- const { data : authResult } = await axios . post ( "https://api.maxrosoff.com/admin/passkey-auth" , {
71- response : authResponse ,
72- challenge : authOptions . challenge
73- } ) ;
74-
75- const existingAdminMode = emulatorState . getAdminConsoleMode ( ) ;
76- emulatorState . setAdminConsoleMode ( {
77- ...existingAdminMode ,
78- authToken : authResult . token
79- } ) ;
80-
81- const commandMapping = emulatorState . getCommandMapping ( ) ;
82- const result = emulator . runCommand ( commandMapping , promptState . targetCommand , [
83- emulatorState ,
84- promptState . targetOptions
85- ] ) ;
86-
87- emulatorState . setPasswordPromptState ( undefined ) ;
88-
89- const outputs = emulatorState . getOutputs ( ) ;
90- if ( outputs . length > 0 ) {
91- const lastOutput = outputs [ outputs . length - 1 ] ;
92- lastOutput . output = [ result ] ;
93- emulatorState . setOutputs ( [ ...outputs ] ) ;
94- }
95-
96- return true ;
97- } catch ( err ) {
98- console . error ( "Authentication Failed:" , err ) ;
99- emulatorState . setPasswordPromptState ( undefined ) ;
100-
101- const outputs = emulatorState . getOutputs ( ) ;
102- if ( outputs . length > 0 ) {
103- const lastOutput = outputs [ outputs . length - 1 ] ;
104- lastOutput . output = [ { output : "Authentication Failed" , type : "error" } ] ;
105- emulatorState . setOutputs ( [ ...outputs ] ) ;
106- }
107- return true ;
79+ const outputs = emulatorState . getOutputs ( ) ;
80+ if ( outputs . length > 0 ) {
81+ const lastOutput = outputs [ outputs . length - 1 ] ;
82+ lastOutput . output = [ result ] ;
83+ emulatorState . setOutputs ( [ ...outputs ] ) ;
84+ }
85+ } catch ( err ) {
86+ console . error ( "Authentication Failed:" , err ) ;
87+ emulatorState . setPasswordPromptState ( undefined ) ;
88+
89+ const outputs = emulatorState . getOutputs ( ) ;
90+ if ( outputs . length > 0 ) {
91+ const lastOutput = outputs [ outputs . length - 1 ] ;
92+ lastOutput . output = [ { output : "Authentication Failed" , type : "error" } ] ;
93+ emulatorState . setOutputs ( [ ...outputs ] ) ;
10894 }
10995 }
110- return false ;
11196} ;
11297
11398export const manPage = `NAME
0 commit comments