Skip to content

Commit 98a48df

Browse files
author
Midoriya-w
committed
fix: replace expo secure store with AsyncStorage
1 parent a0f2892 commit 98a48df

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

apps/mobile/src/context/AuthContext.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { createContext, useContext, useState, useEffect, ReactNode } from 'react';
2-
import * as SecureStore from 'expo-secure-store';
2+
import AsyncStorage from '@react-native-async-storage/async-storage';
33

44
const TOKEN_KEY = 'devcard_auth_token';
55
const API_BASE_URL = process.env.EXPO_PUBLIC_API_URL ?? 'http://localhost:3000';
@@ -28,7 +28,7 @@ export function AuthProvider({ children }: { children: ReactNode }) {
2828
useEffect(() => {
2929
const loadToken = async () => {
3030
try {
31-
const savedToken = await SecureStore.getItemAsync(TOKEN_KEY);
31+
const savedToken = await AsyncStorage.getItem(TOKEN_KEY);
3232
if (savedToken) {
3333
setToken(savedToken);
3434
const res = await fetch(`${API_BASE_URL}/api/profiles/me`, {
@@ -38,7 +38,7 @@ export function AuthProvider({ children }: { children: ReactNode }) {
3838
const userData = await res.json();
3939
setUser(userData);
4040
} else {
41-
await SecureStore.deleteItemAsync(TOKEN_KEY);
41+
await AsyncStorage.removeItem(TOKEN_KEY);
4242
}
4343
}
4444
} catch (err) {
@@ -52,7 +52,7 @@ export function AuthProvider({ children }: { children: ReactNode }) {
5252

5353
const login = async (newToken: string) => {
5454
setToken(newToken);
55-
await SecureStore.setItemAsync(TOKEN_KEY, newToken);
55+
await AsyncStorage.setItem(TOKEN_KEY, newToken);
5656
try {
5757
const res = await fetch(`${API_BASE_URL}/api/profiles/me`, {
5858
headers: { Authorization: `Bearer ${newToken}` },
@@ -69,7 +69,7 @@ export function AuthProvider({ children }: { children: ReactNode }) {
6969
const logout = async () => {
7070
setToken(null);
7171
setUser(null);
72-
await SecureStore.deleteItemAsync(TOKEN_KEY);
72+
await AsyncStorage.removeItem(TOKEN_KEY);
7373
};
7474

7575
return (

0 commit comments

Comments
 (0)