Skip to content

Commit

Permalink
Merge pull request #24 from yurenju/feat/logout
Browse files Browse the repository at this point in the history
Feat/logout
  • Loading branch information
yurenju authored Sep 20, 2023
2 parents a96afc1 + 8d894bc commit b5e7952
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ jobs:

- run: npx nx affected -t e2e
env:
VITE_MOCK_WALLET_PRIVATE_KEY: ${{ secrets.MOCK_WALLET_PRIVATE_KEY }}
VITE_INFURA_PROJECT_ID: ${{ secrets.INFURA_PROJECT_ID }}
# thest are only for testing, DO NOT USE IT FOR OTHER PURPOSE!!
VITE_MOCK_WALLET_PRIVATE_KEY: '0x8b806ec6cc2cbc6f75e1e0a0b020dba4d02f1a8578b9a8e2fb1f53f5a1c83e99'
VITE_INFURA_PROJECT_ID: '25e33bb59b0b4803813c8f238cceb14e'
acceptance:
if: ${{ false }}
runs-on: ubuntu-latest
continue-on-error: true
steps:
Expand Down
2 changes: 1 addition & 1 deletion apps/server/src/national/national.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { JwtStrategy } from './jwt.strategy';
imports: [
JwtModule.register({
secret: jwtConstants.secret,
signOptions: { expiresIn: '60s' },
signOptions: { expiresIn: '7d' },
}),
UsersModule,
PassportModule,
Expand Down
5 changes: 3 additions & 2 deletions apps/web/src/pages/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ChangeEvent, useState } from 'react';

export function Login() {
const [nationalId, setNationalId] = useState<string>('');
const { login } = useAuth();
const { login, logout } = useAuth();

const handleTyping = (e: ChangeEvent<HTMLInputElement>) => {
setNationalId(e.target.value);
Expand All @@ -22,7 +22,8 @@ export function Login() {
onChange={handleTyping}
value={nationalId}
/>
<button onClick={() => handleLogin()}>Login</button>
<button onClick={() => handleLogin()}>Login</button>{' '}
<button onClick={() => logout()}>Logout</button>
</div>
);
}
7 changes: 7 additions & 0 deletions libs/react-library/src/lib/contexts/AuthContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ interface User {
interface AuthContextProps {
user: User | null;
login: (username: string, password: string) => Promise<void>;
logout: () => void;
register: (username: string, password: string) => Promise<void>;
ethereumLogin: () => Promise<void>;
updateSemaphoreCommitment: (semaphoreCommitment: string) => Promise<void>;
Expand Down Expand Up @@ -129,6 +130,11 @@ export const AuthProvider: React.FC<AuthProviderProps> = ({ children }) => {
}
};

const logout = () => {
setUser(null);
localStorage.removeItem('user');
};

const register = async (username: string, password: string) => {
const res = await fetch('/api/auth/national/register', {
method: 'POST',
Expand Down Expand Up @@ -235,6 +241,7 @@ export const AuthProvider: React.FC<AuthProviderProps> = ({ children }) => {
value={{
user,
login,
logout,
register,
ethereumLogin,
updateSemaphoreCommitment,
Expand Down

0 comments on commit b5e7952

Please sign in to comment.