forked from goplus/builder
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add `useEnsureSignedIn` to prompt users to sign in before executing protected actions. - Add similar protection for specific routes using navigation guards. Fixes goplus#974 Signed-off-by: Aofei Sheng <aofei@aofeisheng.com>
- Loading branch information
Showing
10 changed files
with
68 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { useUserStore } from '@/stores' | ||
import { useI18n } from './i18n' | ||
import { useConfirmDialog } from '@/components/ui' | ||
import { Cancelled } from './exception' | ||
|
||
export function useEnsureSignedIn() { | ||
const userStore = useUserStore() | ||
const { t } = useI18n() | ||
const withConfirm = useConfirmDialog() | ||
|
||
return async () => { | ||
if (userStore.isSignedIn()) return | ||
await withConfirm({ | ||
title: t({ en: 'Sign in to continue', zh: '登录以继续' }), | ||
content: t({ | ||
en: 'You need to sign in first to perform this action. Would you like to sign in now?', | ||
zh: '你需要先登录才能执行此操作。你想现在登录吗?' | ||
}), | ||
confirmText: t({ en: 'Sign in', zh: '登录' }), | ||
confirmHandler: () => userStore.initiateSignIn() | ||
}) | ||
throw new Cancelled('redirected to sign in') | ||
} | ||
} |