Skip to content

Commit

Permalink
feat: removed js-cookie and used local storage instead
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyvid7-Darus10 committed May 21, 2023
1 parent b745895 commit 8adc16a
Show file tree
Hide file tree
Showing 12 changed files with 24 additions and 38 deletions.
5 changes: 2 additions & 3 deletions dist/cjs/components/FaceLogin/index.js

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

2 changes: 1 addition & 1 deletion dist/cjs/components/FaceLogin/index.js.map

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

2 changes: 1 addition & 1 deletion dist/cjs/components/useUserData/index.js

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

2 changes: 1 addition & 1 deletion dist/cjs/components/useUserData/index.js.map

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

5 changes: 2 additions & 3 deletions dist/esm/components/FaceLogin/index.js

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

2 changes: 1 addition & 1 deletion dist/esm/components/FaceLogin/index.js.map

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

2 changes: 1 addition & 1 deletion dist/esm/components/useUserData/index.js

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

2 changes: 1 addition & 1 deletion dist/esm/components/useUserData/index.js.map

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

15 changes: 3 additions & 12 deletions package-lock.json

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

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
"typescript": "^4.7.3"
},
"dependencies": {
"@types/js-cookie": "^3.0.3",
"js-cookie": "^3.0.5"
"@types/js-cookie": "^3.0.3"
}
}
5 changes: 2 additions & 3 deletions src/components/FaceLogin/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, { CSSProperties, useEffect } from 'react';
import Cookies from 'js-cookie';

type FaceLoginProps = {
appId: string;
Expand Down Expand Up @@ -35,8 +34,8 @@ const FaceLogin: React.FC<FaceLoginProps> = ({
})
.then((response) => response.json())
.then((data) => {
// Save token in cookie
Cookies.set('token', data.token);
// Save token in local storage
localStorage.setItem('token', data.token);
})
.catch((err) => console.error(err));
}
Expand Down
17 changes: 8 additions & 9 deletions src/components/useUserData/index.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
import { useState, useEffect } from 'react';
import Cookies from 'js-cookie';

const useUserData = () => {
const [userData, setUserData] = useState<any>(null);

useEffect(() => {
// Check if user data already exists in cookie
const existingUserData = Cookies.get('userData');
// Check if user data already exists in local storage
const existingUserData = localStorage.getItem('userData');
if (existingUserData) {
setUserData(existingUserData);
setUserData(JSON.parse(existingUserData));
return;
}

// Get token from cookie
const token = Cookies.get('token');
// Get token from local storage
const token = localStorage.getItem('token');

// Fetch user data if token exists
if (token) {
fetch('/api/get-user', {
fetch('https://www.face-guardian.com/api/get-user', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Expand All @@ -26,8 +25,8 @@ const useUserData = () => {
})
.then((response) => response.json())
.then((data) => {
// Save user data to cookie and state
Cookies.set('userData', JSON.stringify(data));
// Save user data to local storage and state
localStorage.setItem('userData', JSON.stringify(data));
setUserData(data);
})
.catch((err) => console.error(err));
Expand Down

0 comments on commit 8adc16a

Please sign in to comment.