Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(init): fix default user creation bug #130

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions cmd/init/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,25 +63,20 @@ func createDefaultUser(ctx context.Context, db *gorm.DB) error {
CookieToken: sql.NullString{String: "", Valid: false},
}

user, err := r.GetUser(defaultUserUID)
user, err := r.GetUserByID(constant.DefaultUserID)
// Default user already exists
if err == nil {
user.ID = constant.DefaultUserID
passwordHash, _, err := r.GetUserPasswordHash(ctx, defaultUserUID)
passwordHash, _, err := r.GetUserPasswordHash(ctx, user.UID)
if err != nil {
return err
}

if passwordHash == "" {
err = r.UpdateUserPasswordHash(ctx, defaultUserUID, string(passwordBytes), time.Now())
err = r.UpdateUserPasswordHash(ctx, user.UID, string(passwordBytes), time.Now())
if err != nil {
return err
}
}
err = r.UpdateUser(ctx, defaultUserUID, user)
if err != nil {
return err
}
return nil
}

Expand All @@ -94,7 +89,7 @@ func createDefaultUser(ctx context.Context, db *gorm.DB) error {
if err != nil {
return err
}
err = r.UpdateUserPasswordHash(ctx, defaultUserUID, string(passwordBytes), time.Now())
err = r.UpdateUserPasswordHash(ctx, defaultUser.UID, string(passwordBytes), time.Now())
if err != nil {
return err
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/db/migration/000002_init.up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ CREATE TABLE IF NOT EXISTS public.token(
);
CREATE UNIQUE INDEX unique_owner_id_delete_time ON public.token (owner, id);

UPDATE public.user SET id = 'admin' WHERE id = 'instill-ai';

COMMIT;
Loading