Skip to content
This repository has been archived by the owner on Jul 1, 2024. It is now read-only.

Commit

Permalink
Merge pull request #29 from oxygenpay/develop
Browse files Browse the repository at this point in the history
merge: develop
  • Loading branch information
swift1337 authored Aug 17, 2023
2 parents 253b60c + a76367e commit 2761fee
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 32 deletions.
17 changes: 11 additions & 6 deletions internal/db/repository/users.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion internal/service/user/service_google.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
)

func (s *Service) ResolveWithGoogle(ctx context.Context, user *auth.GoogleUser) (*User, error) {
entry, err := s.store.GetUserByGoogleID(ctx, repository.StringToNullable(user.Sub))
entry, err := s.store.GetUserByEmail(ctx, user.Email)
switch {
case errors.Is(err, pgx.ErrNoRows):
return s.registerGoogleUser(ctx, user)
Expand Down Expand Up @@ -57,6 +57,8 @@ func (s *Service) registerGoogleUser(ctx context.Context, user *auth.GoogleUser)
func (s *Service) updateGoogleUser(ctx context.Context, userID int64, user *auth.GoogleUser) (*User, error) {
entry, err := s.store.UpdateUser(ctx, repository.UpdateUserParams{
ID: userID,
SetGoogleID: true,
GoogleID: repository.StringToNullable(user.Sub),
Name: user.Name,
ProfileImageUrl: repository.StringToNullable(user.Picture),
UpdatedAt: time.Now(),
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions pkg/api-kms/v1/client/wallet/wallet_client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions scripts/queries/users.sql
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ RETURNING *;

-- name: UpdateUser :one
UPDATE users
SET name = $1,
profile_image_url= $2,
updated_at = $3
WHERE id = $4
SET name = $2,
profile_image_url= $3,
google_id = CASE WHEN @set_google_id::boolean THEN $4 ELSE users.google_id END,
updated_at = $5
WHERE id = $1
RETURNING *;

-- name: UpdateUserPassword :one
Expand Down
21 changes: 18 additions & 3 deletions ui-dashboard/src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ const App: React.FC = () => {
const [user, setUser] = React.useState<User>();
const [isSupportFormOpen, setIsSupportFormOpen] = React.useState<boolean>(false);
const [isFormSubmitting, setIsFormSubmitting] = React.useState<boolean>(false);
const [isLoading, setIsLoading] = React.useState<boolean>(true);

const loadUserInfo = async () => {
let newMerchantId = merchantId;
Expand All @@ -112,7 +113,11 @@ const App: React.FC = () => {
posthog?.reset(true);
}

navigate("/login");
navigate("/login", {
state: {
isNeedLogout: true
}
});
}
}
};
Expand All @@ -127,7 +132,11 @@ const App: React.FC = () => {
posthog?.reset(true);
}

navigate("/login");
navigate("/login", {
state: {
isNeedLogout: true
}
});
}
}
};
Expand All @@ -154,6 +163,7 @@ const App: React.FC = () => {
if (!newMerchantId) return;

await getMerchant(newMerchantId);
setIsLoading(false);
};

await getCookie();
Expand Down Expand Up @@ -210,7 +220,11 @@ const App: React.FC = () => {
}

await authProvider.logout();
navigate("/login");
navigate("/login", {
state: {
isNeedLogout: true
}
});
};

const userMenu: MenuProps["items"] = [
Expand Down Expand Up @@ -277,6 +291,7 @@ const App: React.FC = () => {
)}
</RouteContext.Consumer>
}
loading={isLoading}
actionsRender={() => {
return [
!isManageMerchantsActive ? (
Expand Down
24 changes: 22 additions & 2 deletions ui-dashboard/src/pages/login-page/login-page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import "./login-page.scss";

import * as React from "react";
import {useNavigate} from "react-router-dom";
import {AxiosError} from "axios";
import {useNavigate, useLocation} from "react-router-dom";
import {Modal, Button, Typography, Form, Input, notification} from "antd";
import {GoogleOutlined, CheckOutlined} from "@ant-design/icons";
import logoImg from "/fav/android-chrome-192x192.png";
Expand All @@ -15,12 +16,17 @@ import SpinWithMask from "src/components/spin-with-mask/spin-with-mask";

const b = bevis("login-page");

interface LoginState {
isNeedLogout: boolean;
}

const LoginPage: React.FC = () => {
const [form] = Form.useForm<UserCreateForm>();
const [api, contextHolder] = notification.useNotification();
const [isFormSubmitting, setIsFormSubmitting] = React.useState<boolean>(false);
const [providersList, setProvidersList] = React.useState<AuthProvider[]>([]);
const navigate = useNavigate();
const state: LoginState = useLocation().state;

const openNotification = (title: string, description: string) => {
api.info({
Expand Down Expand Up @@ -60,7 +66,21 @@ const LoginPage: React.FC = () => {

useMount(async () => {
window.addEventListener("popstate", () => navigate("/login", {replace: true}));
localStorage.remove("merchantId");

if (state?.isNeedLogout) {
localStorage.remove("merchantId");
} else {
try {
await authProvider.getCookie();
await authProvider.getMe();
navigate("/");
} catch (e) {
if (e instanceof AxiosError && e.response?.status === 401) {
localStorage.remove("merchantId");
}
}
}

const availProviders = await authProvider.getProviders();
setProvidersList(availProviders ?? []);
});
Expand Down

0 comments on commit 2761fee

Please sign in to comment.