Skip to content

Commit

Permalink
fix: token set
Browse files Browse the repository at this point in the history
  • Loading branch information
YoanRos committed Sep 13, 2024
1 parent 16101af commit f28d643
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 18 deletions.
6 changes: 3 additions & 3 deletions api/src/controllers/goal.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ router.post(
id: `${user.id}_${date}`,
userId: user.id,
date,
daysWithGoalNoDrink: user.goal_daysWithGoalNoDrink,
dosesByDrinkingDay: user.goal_dosesByDrinkingDay,
dosesPerWeek: user.goal_dosesPerWeek,
daysWithGoalNoDrink: daysWithGoalNoDrink,
dosesByDrinkingDay: dosesByDrinkingDay,
dosesPerWeek: dosesPerWeek,
status: GoalStatus.InProgress,
},
});
Expand Down
2 changes: 1 addition & 1 deletion expo/src/Router.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ const App = () => {
);
const [isTokenValid, setIsTokenValid] = useState(null);
const token = storage.getString("@Token");
API.setToken(token);

useEffect(() => {
const checkTokenValidity = async () => {
Expand All @@ -201,7 +202,6 @@ const App = () => {
try {
const response = await API.get({
path: "/user/signin_token",
headers: { Authorization: `Bearer ${token}` },
});

if (response.ok) {
Expand Down
1 change: 1 addition & 0 deletions expo/src/scenes/Auth/Signin.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const SigninScreen = ({ navigation }) => {
});
if (response.ok) {
API.setToken(response.token);
storage.set("@Token", response.token);
if (!reconciliatedDrinksToDB) {
await reconciliateDrinksToDB();
setReconciliatedDrinksToDB(true);
Expand Down
34 changes: 22 additions & 12 deletions expo/src/scenes/Auth/Signup.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,16 @@ import {
migrateFromDailyGoalToWeekly,
migrateMissingDrinkKey,
} from "../../migrations";
import RNRestart from "react-native-restart";

const SignupScreen = ({ navigation }) => {
const [reconciliatedDrinksToDB, setReconciliatedDrinksToDB] = useState(false);
const [reconciliatedGoalsToDB, setReconciliatedGoalsToDB] = useState(false);
const [hasSentPreviousDrinksToDB, setHasSentPreviousDrinksToDB] = useState(hasSentPreviousDrinksToDB);
const [hasCleanConsoAndCatalog, setHasCleanConsoAndCatalog] = useState(hasCleanConsoAndCatalog);
const [hasMigrateFromDailyGoalToWeekly, sethasMigrateFromDailyGoalToWeekly] = useState(
hasMigrateFromDailyGoalToWeekly
);
const [hasMigrateMissingDrinkKey, sethasMigrateMissingDrinkKey] = useState(hasMigrateMissingDrinkKey);
const [email, setEmail] = useState("");
const [password, setPassword] = useState("");
Expand Down Expand Up @@ -83,18 +87,24 @@ const SignupScreen = ({ navigation }) => {
if (response.ok) {
storage.set("@User", response.newUser.email);
API.setToken(response.token);
await reconciliateDrinksToDB();
setReconciliatedDrinksToDB(true);
await reconciliateGoalToDB();
setReconciliatedGoalsToDB(true);
await cleanConsosAndCatalog();
setHasCleanConsoAndCatalog(true);
await sendPreviousDrinksToDB();
setHasSentPreviousDrinksToDB(true);
await migrateFromDailyGoalToWeekly();
sethasMigrateFromDailyGoalToWeekly(true);
migrateMissingDrinkKey();
sethasMigrateMissingDrinkKey(true);
storage.set("@Token", response.token);
const imported = storage.getBoolean("@imported");
if (imported) {
await reconciliateDrinksToDB();
setReconciliatedDrinksToDB(true);
await reconciliateGoalToDB();
setReconciliatedGoalsToDB(true);
await cleanConsosAndCatalog();
setHasCleanConsoAndCatalog(true);
await sendPreviousDrinksToDB();
setHasSentPreviousDrinksToDB(true);
await migrateFromDailyGoalToWeekly();
sethasMigrateFromDailyGoalToWeekly(true);
migrateMissingDrinkKey();
sethasMigrateMissingDrinkKey(true);
RNRestart.Restart();
}

navigation.navigate("EMAIL_CONFIRMATION");
} else {
alert("Erreur lors de l'inscription");
Expand Down
4 changes: 2 additions & 2 deletions expo/src/scenes/WelcomeScreen/ScreensOldUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { logEvent } from "../../services/logEventsWithMatomo";
import { storage } from "../../services/storage";
import * as DocumentPicker from "expo-document-picker";
import { Alert } from "react-native";
import RNRestart from "react-native-restart";
import API from "../../services/api";
import AntDesign from "@expo/vector-icons/AntDesign";

Expand Down Expand Up @@ -150,6 +149,7 @@ const overwriteData = async (dataImported, pushNotifToken) => {
storage.clearAll();
if (pushNotifToken) {
storage.set("STORAGE_KEY_PUSH_NOTIFICATION_TOKEN", pushNotifToken);
storage.set("@imported", true);
}
Object.keys(dataImported).forEach((key) => {
const value = dataImported[key];
Expand All @@ -160,7 +160,7 @@ const overwriteData = async (dataImported, pushNotifToken) => {
}
});

await API.put({ path: `/user`, body: { matomoId: dataImported["@UserIdv2"], pushNotifToken } }).then((res) => {
await API.put({ path: `/user`, body: { pushNotifToken } }).then((res) => {
if (res.ok) {
logEvent({ category: "TRANSFER", action: "IMPORT_DATA_SUCCESS" });
} else {
Expand Down

0 comments on commit f28d643

Please sign in to comment.