Skip to content

Commit

Permalink
update login
Browse files Browse the repository at this point in the history
  • Loading branch information
SergioLangaritaBenitez committed Oct 21, 2024
1 parent b931a34 commit f62fc0e
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 17 deletions.
1 change: 1 addition & 0 deletions public/callback.html
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
"user":{ 'access_token': tokens['access_token'], info:users } ,
"token": tokens['access_token'],
"endpoint": localStorage.getItem('api')})

localStorage.setItem("authData",authData);
var url_redirect = window.location.origin + "/#/ui/services"
window.location.href = url_redirect
Expand Down
29 changes: 18 additions & 11 deletions src/api/info/getInfoApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,40 @@ type GetInfoProps = {
endpoint: string;
username: string;
password: string;
token: string;
token: string | undefined;
};

export async function getInfoApi({
endpoint,
username,
password,
token,
password,
}: GetInfoProps) {
let config
if (token!=""){
config = {
baseURL: endpoint,
headers: {
'Authorization': 'Bearer ' + token
}
}
}else{
console.log(username)
console.log(password)
console.log(token)
let config={}
if ( token !== undefined) {
config = {
baseURL: endpoint,
auth: {
username,
password,
},
}
}else{
config = {
baseURL: endpoint,
headers: { Authorization: "Bearer "+token},
auth: undefined,
}
}
console.log(config)

const response = await axios.get("/system/info", config);
console.log(response)

return response.data;
}


8 changes: 3 additions & 5 deletions src/contexts/AuthContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export type AuthData = {
user: string;
password: string;
endpoint: string;
token: string;
token: string | undefined;
authenticated?: boolean;
};

Expand All @@ -23,7 +23,6 @@ export const AuthContext = createContext({
user: "",
password: "",
endpoint: "",
token: "",
authenticated: false,
} as AuthData,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
Expand All @@ -39,7 +38,6 @@ export const AuthProvider = ({ children }: { children: React.ReactNode }) => {
user: "",
password: "",
endpoint: "",
token: "",
authenticated: false,
} as AuthData;
}
Expand Down Expand Up @@ -84,14 +82,14 @@ export const AuthProvider = ({ children }: { children: React.ReactNode }) => {
endpoint: authData.endpoint,
username: authData.user,
password: authData.password,
token: authData.token,
token: (authData?.token) ? (authData.token) : (undefined),
});
} catch (error) {
setAuthData({
user: "",
password: "",
endpoint: "",
token: "",
token:"",
authenticated: false,
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Login/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function Login() {
authenticated: true,
user: username,
password,
token,
token: undefined,
endpoint,
});
} catch (error) {
Expand Down

0 comments on commit f62fc0e

Please sign in to comment.