Skip to content

Commit 08eda5f

Browse files
committed
Check login status before creating snippets
1 parent f13a5d2 commit 08eda5f

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/commands/snippet.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
import * as vscode from 'vscode';
22
import { API } from './../api';
3+
import { checkLogin } from './../utils';
34

45
export function registerSnippetCommands(context: vscode.ExtensionContext) {
56
context.subscriptions.push(vscode.commands.registerCommand('HackMD.createCodeSnippet', async () => {
7+
if (!(await checkLogin())){
8+
vscode.window.showInformationMessage('Please login first.');
9+
return;
10+
}
11+
612
const editor = vscode.window.activeTextEditor;
713
if (editor.selection.isEmpty) {
814
vscode.window.showInformationMessage('The code block is empty. Please select a range of text first.');

src/utils.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { API } from './api';
2+
3+
export const checkLogin = async () => {
4+
return (await API.getMe()).status === 'ok';
5+
};

0 commit comments

Comments
 (0)