如何使用角色?
login = async (creds: UserFormValues) => {
try {
const user = await agent.Account.login(creds);
store.commonStore.setToken(user.token);
runInAction(() => this.user = user);
history.push('/activities');
store.modalStore.closeModal();
} catch (error) {
throw error;
}
}
我有这个“登录”,我想编辑它以扮演角色。喜欢:
login = async (creds: UserFormValues) => {
try {
const user = await agent.Account.login(creds);
store.commonStore.setToken(user.token);
runInAction(() => this.user = user);
if(user.role = "admin"){
history.push('/activities');
}
else{
history.push('/home');
}
store.modalStore.closeModal();
} catch (error) {
throw error;
}
}
但是我得到了警告
期望有条件的表达式,而是看到了一个分配无核对
,并且该平台仍在运行,但它忽略了if语句。如何对此做出有条件的表达(如果您还可以向我展示有关它的代码)?另外,我有5个角色应该在不同的页面上进行。
login = async (creds: UserFormValues) => {
try {
const user = await agent.Account.login(creds);
store.commonStore.setToken(user.token);
runInAction(() => this.user = user);
if(user.role === "admin"){
history.push('/activities');
}
else{
history.push('/home');
}
store.modalStore.closeModal();
} catch (error) {
throw error;
}
}
这是更新的代码,当我登录Admin时,它将我重定向到家而不是活动,例如不存在。
login = async (creds: UserFormValues) => {
try {
const user = await agent.Account.login(creds);
store.commonStore.setToken(user.token);
runInAction(() => this.user = user);
history.push('/activities');
store.modalStore.closeModal();
} catch (error) {
throw error;
}
}
I have this "login" that I want to edit it to make it with roles. Like:
login = async (creds: UserFormValues) => {
try {
const user = await agent.Account.login(creds);
store.commonStore.setToken(user.token);
runInAction(() => this.user = user);
if(user.role = "admin"){
history.push('/activities');
}
else{
history.push('/home');
}
store.modalStore.closeModal();
} catch (error) {
throw error;
}
}
But I get the warning
Expected a conditional expression and instead saw an assignment no-cond-assign
and still the platform runs but it ignores the if statement. How can I make a conditional expression about this(If you can also show me the code about it)? Also I have 5 roles which should go all on different pages.
login = async (creds: UserFormValues) => {
try {
const user = await agent.Account.login(creds);
store.commonStore.setToken(user.token);
runInAction(() => this.user = user);
if(user.role === "admin"){
history.push('/activities');
}
else{
history.push('/home');
}
store.modalStore.closeModal();
} catch (error) {
throw error;
}
}
This is the updated code, when I login as admin it redirects me to home and not into activities, like the if doesn't exist.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论