Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/logout #24

Merged
merged 4 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading