chore: no need to expire auth token
All checks were successful
Release / build_and_release (push) Successful in 43s
All checks were successful
Release / build_and_release (push) Successful in 43s
This commit is contained in:
parent
2ed092bcbd
commit
e57893b1b2
@ -10,7 +10,7 @@ import {
|
||||
saveAuthToken
|
||||
} from '../utils'
|
||||
import { appPrivateRoutes } from '../routes'
|
||||
import { AuthToken, SignedEvent } from '../types'
|
||||
import { SignedEvent } from '../types'
|
||||
|
||||
export class AuthController {
|
||||
private nostrController: NostrController
|
||||
@ -76,8 +76,8 @@ export class AuthController {
|
||||
checkSession() {
|
||||
const savedAuthToken = getAuthToken()
|
||||
|
||||
if (savedAuthToken && this.isTokenValid(savedAuthToken)) {
|
||||
const signedEvent = base64DecodeAuthToken(savedAuthToken.token)
|
||||
if (savedAuthToken) {
|
||||
const signedEvent = base64DecodeAuthToken(savedAuthToken)
|
||||
|
||||
store.dispatch(
|
||||
setAuthState({
|
||||
@ -97,25 +97,11 @@ export class AuthController {
|
||||
)
|
||||
}
|
||||
|
||||
private isTokenValid(authToken: AuthToken): boolean {
|
||||
const timeNow = Math.round(Date.now() / 1000)
|
||||
const eventExpiresAt = authToken.expiresAt
|
||||
const timeDifference = eventExpiresAt - timeNow
|
||||
|
||||
// check if previous authToken has expired or not
|
||||
if (timeDifference > 0) {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
private createAndSaveAuthToken(signedAuthEvent: SignedEvent) {
|
||||
const base64Encoded = base64EncodeSignedEvent(signedAuthEvent)
|
||||
|
||||
// save newly created auth token (base64 nostr singed event) in local storage along with expiry time
|
||||
const createdAt = Math.round(Date.now() / 1000)
|
||||
saveAuthToken(base64Encoded, createdAt + 3600) // 3600 secs = 1 hour
|
||||
saveAuthToken(base64Encoded)
|
||||
return base64Encoded
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +0,0 @@
|
||||
export interface AuthToken {
|
||||
token: string
|
||||
expiresAt: number
|
||||
}
|
@ -1,3 +1,2 @@
|
||||
export * from './auth'
|
||||
export * from './nostr'
|
||||
export * from './profile'
|
||||
|
@ -1,5 +1,4 @@
|
||||
import { State } from '../store/rootReducer'
|
||||
import { AuthToken } from '../types'
|
||||
|
||||
export const saveState = (state: object) => {
|
||||
try {
|
||||
@ -55,26 +54,12 @@ export const getVisitedLink = () => {
|
||||
}
|
||||
}
|
||||
|
||||
export const saveAuthToken = (token: string, expiresAt: number) => {
|
||||
localStorage.setItem(
|
||||
'authToken',
|
||||
JSON.stringify({
|
||||
token,
|
||||
expiresAt
|
||||
})
|
||||
)
|
||||
export const saveAuthToken = (token: string) => {
|
||||
localStorage.setItem('authToken', token)
|
||||
}
|
||||
|
||||
export const getAuthToken = () => {
|
||||
const serializedAuthDetail = localStorage.getItem('authToken')
|
||||
|
||||
if (!serializedAuthDetail) return null
|
||||
|
||||
try {
|
||||
return JSON.parse(serializedAuthDetail) as AuthToken
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
return localStorage.getItem('authToken')
|
||||
}
|
||||
|
||||
export const clearAuthToken = () => {
|
||||
|
Loading…
Reference in New Issue
Block a user