asyns invoke in tauri
Unanswered
Brown bear posted this in #help-forum
![Avatar](https://cdn.discordapp.com/embed/avatars/1.png)
Brown bearOP
sup guys, I'm making my tauri app using next.js
I wanna add simple auth function and invoke it from my login.tsx file:
this my main.rs:
When I trying to run tauri dev and tap button after enter 123 in login input I see this problem:
If I delete async/await - I still have this problem
I wanna add simple auth function and invoke it from my login.tsx file:
import Image from 'next/image'
import { useContext, useState, useEffect } from 'react'
import { RouterContext, RoutingEnum } from '../providers/router.provider'
import { invoke } from '@tauri-apps/api/tauri'
export default function Login() {
const { route } = useContext(RouterContext)
const [state, setState] = useState<string>('')
const buttonHandler = async() => {
await invoke('license_command', {key: state}).then((res) => {
if (res) {
route(RoutingEnum.TASKS)
} else {
setState("WRONG KEY")
}
})
}
return (
<>
<div className='login-container'>
<Image
src='/eviler-logo-block.svg'
alt='Eviler Logo'
width={400}
height={106}
/>
<input className='login-input'
placeholder='Enter your code'
value={state}
onChange={(e) => {
setState(e.target.value)
}}
/>
<button className='login-button' onClick={buttonHandler}>Login</button>
</div>
</>
)
}
this my main.rs:
// main.rs
#[tauri::command]
fn license_command(key: &str) -> bool{
let is_authorized = key;
if key == "123" {
true
}
else{
false
}
}
fn main() {
tauri::Builder::default()
.invoke_handler(tauri::generate_handler![license_command])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
When I trying to run tauri dev and tap button after enter 123 in login input I see this problem:
Unhandled Runtime Error
Error: async/await is not yet supported in Client Components, only Server Components. This error is often caused by accidentally adding `'use client'` to a module that was originally written for the server.
If I delete async/await - I still have this problem
1 Reply
![Avatar](https://cdn.discordapp.com/embed/avatars/1.png)
Brown bearOP
Also If i delete async and await from buttonHandler function - I still have this problem