Skip to content

armgit / memos

Public Imported from GitHub
0

Memos is an open-source, self-hosted note-taking app that brings your everyday thoughts together in a personal timeline. Your data stays yours, and you choose what to keep private or share.

feat: seed data only in dev mode (#61)

STEVENd6680a0bcc77
diff --git a/store/seed/10001__user.sql b/store/seed/10001__user.sql
index dd23f6b6b..efd536753 100644
--- a/store/seed/10001__user.sql
+++ b/store/seed/10001__user.sql
@@ -1,17 +1,19 @@
INSERT INTO
user (
`id`,
- `name`,
`email`,
+ `role`,
+ `name`,
`open_id`,
`password_hash`
)
VALUES
(
101,
- 'guest',
- 'guest_open_id',
+ 'OWNER',
+ 'Steven',
+ 'steven_open_id',
-- raw password: secret
'$2a$14$ajq8Q7fbtFRQvXpdCq7Jcuy.Rx1h/L4J60Otx.gyNLbAYctGMJ9tK'
);
diff --git a/store/sqlite.go b/store/sqlite.go
index f04c12638..81977df9c 100644
--- a/store/sqlite.go
+++ b/store/sqlite.go
@@ -54,8 +54,11 @@ func (db *DB) Open() (err error) {
if err := db.migrate(); err != nil {
return fmt.Errorf("failed to migrate: %w", err)
}
- if err := db.seed(); err != nil {
- return fmt.Errorf("failed to seed: %w", err)
+ // If mode is dev, then seed the database.
+ if db.mode == "dev" {
+ if err := db.seed(); err != nil {
+ return fmt.Errorf("failed to seed: %w", err)
+ }
}
} else {
// If db file exists and mode is dev, we should migrate and seed the database.
diff --git a/web/src/less/signin.less b/web/src/less/signin.less
index 2808cf563..08ab0dc99 100644
--- a/web/src/less/signin.less
+++ b/web/src/less/signin.less
@@ -68,14 +68,6 @@
@apply cursor-wait opacity-80;
}
}
-
- > .btn-text {
- @apply text-sm;
- }
-
- > .split-text {
- @apply text-gray-400 mx-2;
- }
}
> .tip-text {
diff --git a/web/src/pages/Signin.tsx b/web/src/pages/Signin.tsx
index af777c81b..8123c89aa 100644
--- a/web/src/pages/Signin.tsx
+++ b/web/src/pages/Signin.tsx
@@ -25,6 +25,10 @@ const Signin: React.FC<Props> = () => {
useEffect(() => {
api.getSystemStatus().then((status) => {
setSiteOwner(status.owner);
+ if (status.profile.mode === "dev") {
+ setEmail("[email protected]");
+ setPassword("secret");
+ }
pageLoadingState.setFinish();
});
}, []);
@@ -105,28 +109,6 @@ const Signin: React.FC<Props> = () => {
actionBtnLoadingState.setFinish();
};
- const handleAutoSigninAsGuestBtnClick = async () => {
- if (actionBtnLoadingState.isLoading) {
- return;
- }
-
- try {
- actionBtnLoadingState.setLoading();
- await api.login("[email protected]", "secret");
-
- const user = await userService.doSignIn();
- if (user) {
- locationService.replaceHistory("/");
- } else {
- toastHelper.error("😟 Login failed");
- }
- } catch (error: any) {
- console.error(error);
- toastHelper.error("😟 " + error.message);
- }
- actionBtnLoadingState.setFinish();
- };
-
return (
<div className={`page-wrapper signin ${pageLoadingState.isLoading ? "hidden" : ""}`}>
<div className="page-container">
@@ -149,10 +131,6 @@ const Signin: React.FC<Props> = () => {
</div>
</div>
<div className="action-btns-container">
- <button className={`btn ${actionBtnLoadingState.isLoading ? "requesting" : ""}`} onClick={handleAutoSigninAsGuestBtnClick}>
- Login as Guest
- </button>
- <span className="split-text">/</span>
{siteOwner ? (
<button
className={`btn signin-btn ${actionBtnLoadingState.isLoading ? "requesting" : ""}`}